﻿Imports Microsoft.VisualBasic
Imports System.Xml
Imports System.IO
Imports System.Web.Configuration
Imports ADOEntityAMLO1059

Public Class clsAmloXML
    Private clsDateFormat As clsDateFormat

    Public Function AddAMLO1node(ByVal filePath As String, ByVal pAmlo1Data As clsAmlo1Data, ByVal pCountPsn As Integer, ByVal pAmlo1Psn() As clsAmlo1Psn, ByVal intLoop As Integer, ByVal intMaxLoop As Integer) As Boolean
        Try
            Dim i As Integer
            Dim xmldoc As XmlDocument
            xmldoc = New XmlDocument()
            xmldoc.Load(filePath)
            Dim parentNode As XmlElement
            parentNode = xmldoc.CreateElement("doc")
            Dim a0_version As XmlElement
            Dim a0_org As XmlElement
            Dim xmla0_version As XmlText
            Dim xmla0_org As XmlText
            clsDateFormat = New clsDateFormat

            If Not (IsDBNull(xmldoc.DocumentElement)) Then
                xmldoc.DocumentElement.PrependChild(parentNode)
                If (intLoop = intMaxLoop) Then
                    a0_org = xmldoc.CreateElement("org")
                    a0_version = xmldoc.CreateElement("version")

                    xmla0_org = xmldoc.CreateTextNode("ธนาคารอาคารสงเคราะห์")
                    xmla0_version = xmldoc.CreateTextNode("1.1")

                    xmldoc.DocumentElement.PrependChild(a0_org)
                    xmldoc.DocumentElement.PrependChild(a0_version)

                    a0_org.AppendChild(xmla0_org)
                    a0_version.AppendChild(xmla0_version)

                End If

            End If

            ' Create the required nodes 

            Dim a1_type As XmlElement
            Dim a1_reportid As XmlElement
            Dim a1_revision As XmlElement
            Dim a1_date As XmlElement
            'cnd==========Begin==================
            Dim a1_cnd As XmlElement
            'name-------------------
            Dim a1_cnd_name As XmlElement
            Dim a1_cnd_name_prefix As XmlElement
            Dim a1_cnd_name_first As XmlElement
            Dim a1_cnd_name_middle As XmlElement
            Dim a1_cnd_name_last As XmlElement
            'id------------------------
            Dim a1_cnd_id As XmlElement
            Dim a1_cnd_id_no As XmlElement
            Dim a1_cnd_id_type As XmlElement
            'location-----------------
            Dim a1_cnd_location As XmlElement
            Dim a1_cnd_location_addr As XmlElement
            Dim a1_cnd_location_phone As XmlElement
            Dim a1_cnd_location_fax As XmlElement
            'office-----------------
            Dim a1_cnd_office As XmlElement
            Dim a1_cnd_office_occ As XmlElement
            Dim a1_cnd_office_desc As XmlElement
            Dim a1_cnd_office_org As XmlElement
            Dim a1_cnd_office_phone As XmlElement
            Dim a1_cnd_office_fax As XmlElement
            'contact----------------
            Dim a1_cnd_contact As XmlElement
            Dim a1_cnd_contact_addr As XmlElement
            Dim a1_cnd_contact_phone As XmlElement
            Dim a1_cnd_contact_fax As XmlElement
            'iddoc----------------
            Dim a1_cnd_iddoc As XmlElement
            Dim a1_cnd_iddoc_type As XmlElement
            Dim a1_cnd_iddoc_desc As XmlElement
            Dim a1_cnd_iddoc_no As XmlElement
            Dim a1_cnd_iddoc_by As XmlElement
            Dim a1_cnd_iddoc_date As XmlElement
            Dim a1_cnd_iddoc_expire As XmlElement
            'cnd==========End==================
            'psn==========Begin==================
            Dim a1_psn(pCountPsn) As XmlElement
            Dim a1_psn_relation(pCountPsn) As XmlElement
            'name-------------------
            Dim a1_psn_name(pCountPsn) As XmlElement
            Dim a1_psn_name_prefix(pCountPsn) As XmlElement
            Dim a1_psn_name_first(pCountPsn) As XmlElement
            Dim a1_psn_name_middle(pCountPsn) As XmlElement
            Dim a1_psn_name_last(pCountPsn) As XmlElement
            'id------------------------
            Dim a1_psn_id(pCountPsn) As XmlElement
            Dim a1_psn_id_no(pCountPsn) As XmlElement
            Dim a1_psn_id_type(pCountPsn) As XmlElement
            'location-----------------
            Dim a1_psn_location(pCountPsn) As XmlElement
            Dim a1_psn_location_addr(pCountPsn) As XmlElement
            Dim a1_psn_location_phone(pCountPsn) As XmlElement
            Dim a1_psn_location_fax(pCountPsn) As XmlElement
            'office-----------------
            Dim a1_psn_office(pCountPsn) As XmlElement
            Dim a1_psn_office_occ(pCountPsn) As XmlElement
            Dim a1_psn_office_org(pCountPsn) As XmlElement
            Dim a1_psn_office_phone(pCountPsn) As XmlElement
            Dim a1_psn_office_fax(pCountPsn) As XmlElement
            Dim a1_psn_office_type(pCountPsn) As XmlElement
            Dim a1_psn_office_desc(pCountPsn) As XmlElement
            'contact----------------
            Dim a1_psn_contact(pCountPsn) As XmlElement
            Dim a1_psn_contact_addr(pCountPsn) As XmlElement
            Dim a1_psn_contact_phone(pCountPsn) As XmlElement
            Dim a1_psn_contact_fax(pCountPsn) As XmlElement
            'iddoc----------------
            Dim a1_psn_iddoc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_type(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_desc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_no(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_by(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_date(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_expire(pCountPsn) As XmlElement
            'psn==========End==================

            'tsc==========Begin==================
            Dim a1_tsc As XmlElement
            Dim a1_tsc_date As XmlElement
            'contact----------------
            Dim a1_tsc_item As XmlElement
            Dim a1_tsc_item_type As XmlElement
            Dim a1_tsc_item_desc As XmlElement
            Dim a1_tsc_item_accno As XmlElement
            'Dim a1_tsc_item_cur As XmlElement
            Dim a1_tsc_item_amt As XmlElement
            'name-------------------
            Dim a1_tsc_name As XmlElement
            Dim a1_tsc_name_prefix As XmlElement
            Dim a1_tsc_name_first As XmlElement
            Dim a1_tsc_name_middle As XmlElement
            Dim a1_tsc_name_last As XmlElement
            'obj----------------
            Dim a1_tsc_obj As XmlElement
            Dim a1_tsc_obj_type As XmlElement
            Dim a1_tsc_obj_desc As XmlElement
            'tsc==========End==================
            'record==========Begin==================
            Dim a1_record As XmlElement
            Dim a1_record_writer As XmlElement
            Dim a1_record_sign As XmlElement
            Dim a1_record_date As XmlElement
            'record==========End==================



            a1_type = xmldoc.CreateElement("type")
            a1_reportid = xmldoc.CreateElement("reportid")
            a1_revision = xmldoc.CreateElement("revision")
            a1_date = xmldoc.CreateElement("date")
            'cnd==========Begin==================
            a1_cnd = xmldoc.CreateElement("cnd")
            'name-------------------
            a1_cnd_name = xmldoc.CreateElement("name")
            a1_cnd_name_prefix = xmldoc.CreateElement("prefix")
            a1_cnd_name_first = xmldoc.CreateElement("first")
            a1_cnd_name_middle = xmldoc.CreateElement("middle")
            a1_cnd_name_last = xmldoc.CreateElement("last")
            'id------------------------
            a1_cnd_id = xmldoc.CreateElement("id")
            a1_cnd_id_no = xmldoc.CreateElement("no")
            a1_cnd_id_type = xmldoc.CreateElement("type")
            'location-----------------
            a1_cnd_location = xmldoc.CreateElement("location")
            a1_cnd_location_addr = xmldoc.CreateElement("addr")
            a1_cnd_location_phone = xmldoc.CreateElement("phone")
            a1_cnd_location_fax = xmldoc.CreateElement("fax")
            'office-----------------
            a1_cnd_office = xmldoc.CreateElement("office")
            a1_cnd_office_occ = xmldoc.CreateElement("occ")
            a1_cnd_office_desc = xmldoc.CreateElement("desc")
            a1_cnd_office_org = xmldoc.CreateElement("org")
            a1_cnd_office_phone = xmldoc.CreateElement("phone")
            a1_cnd_office_fax = xmldoc.CreateElement("fax")
            'contact----------------
            a1_cnd_contact = xmldoc.CreateElement("contact")
            a1_cnd_contact_addr = xmldoc.CreateElement("addr")
            a1_cnd_contact_phone = xmldoc.CreateElement("phone")
            a1_cnd_contact_fax = xmldoc.CreateElement("fax")
            'iddoc----------------

            a1_cnd_iddoc = xmldoc.CreateElement("iddoc")
            a1_cnd_iddoc_type = xmldoc.CreateElement("type")
            a1_cnd_iddoc_desc = xmldoc.CreateElement("desc")
            a1_cnd_iddoc_no = xmldoc.CreateElement("no")
            a1_cnd_iddoc_by = xmldoc.CreateElement("by")
            a1_cnd_iddoc_date = xmldoc.CreateElement("date")
            a1_cnd_iddoc_expire = xmldoc.CreateElement("expire")
            'cnd==========End==================

            For i = 1 To pCountPsn
                'psn==========Begin==================
                a1_psn(i) = xmldoc.CreateElement("psn")
                a1_psn_relation(i) = xmldoc.CreateElement("relation")
                'name-------------------
                a1_psn_name(i) = xmldoc.CreateElement("name")
                a1_psn_name_prefix(i) = xmldoc.CreateElement("prefix")
                a1_psn_name_first(i) = xmldoc.CreateElement("first")
                a1_psn_name_middle(i) = xmldoc.CreateElement("middle")
                a1_psn_name_last(i) = xmldoc.CreateElement("last")
                'id------------------------
                a1_psn_id(i) = xmldoc.CreateElement("id")
                a1_psn_id_no(i) = xmldoc.CreateElement("no")
                a1_psn_id_type(i) = xmldoc.CreateElement("type")
                'location-----------------
                a1_psn_location(i) = xmldoc.CreateElement("location")
                a1_psn_location_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_location_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_location_fax(i) = xmldoc.CreateElement("fax")
                'office-----------------
                a1_psn_office(i) = xmldoc.CreateElement("office")
                a1_psn_office_occ(i) = xmldoc.CreateElement("occ")
                a1_psn_office_org(i) = xmldoc.CreateElement("org")
                a1_psn_office_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_office_fax(i) = xmldoc.CreateElement("fax")
                a1_psn_office_type(i) = xmldoc.CreateElement("type")
                a1_psn_office_desc(i) = xmldoc.CreateElement("desc")
                'contact----------------
                a1_psn_contact(i) = xmldoc.CreateElement("contact")
                a1_psn_contact_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_contact_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_contact_fax(i) = xmldoc.CreateElement("fax")
                'iddoc----------------
                a1_psn_iddoc(i) = xmldoc.CreateElement("iddoc")
                a1_psn_iddoc_type(i) = xmldoc.CreateElement("type")
                a1_psn_iddoc_desc(i) = xmldoc.CreateElement("desc")
                a1_psn_iddoc_no(i) = xmldoc.CreateElement("no")
                a1_psn_iddoc_by(i) = xmldoc.CreateElement("by")
                a1_psn_iddoc_date(i) = xmldoc.CreateElement("date")
                a1_psn_iddoc_expire(i) = xmldoc.CreateElement("expire")
                'psn==========End==================
            Next


            'tsc==========Begin==================
            a1_tsc = xmldoc.CreateElement("tsc")
            a1_tsc_date = xmldoc.CreateElement("date")
            'contact----------------
            a1_tsc_item = xmldoc.CreateElement("item")
            a1_tsc_item_type = xmldoc.CreateElement("type")
            a1_tsc_item_desc = xmldoc.CreateElement("desc")
            a1_tsc_item_accno = xmldoc.CreateElement("accno")
            'a1_tsc_item_cur = xmldoc.CreateElement("cur")
            a1_tsc_item_amt = xmldoc.CreateElement("amt")
            'name-------------------
            a1_tsc_name = xmldoc.CreateElement("name")
            a1_tsc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_name_first = xmldoc.CreateElement("first")
            a1_tsc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_name_last = xmldoc.CreateElement("last")
            'obj----------------
            a1_tsc_obj = xmldoc.CreateElement("obj")
            a1_tsc_obj_type = xmldoc.CreateElement("type")
            a1_tsc_obj_desc = xmldoc.CreateElement("desc")
            'tsc==========End==================
            'record==========Begin==================
            a1_record = xmldoc.CreateElement("record")
            a1_record_writer = xmldoc.CreateElement("writer")
            a1_record_sign = xmldoc.CreateElement("sign")
            a1_record_date = xmldoc.CreateElement("date")
            'record==========End==================

            Dim xmla1_type As XmlText
            Dim xmla1_reportid As XmlText
            Dim xmla1_revision As XmlText
            Dim xmla1_date As XmlText
            'cnd==========Begin==================
            ' Dim xmla1_cnd As XmlText
            'name-------------------
            'Dim xmla1_cnd_name As XmlText
            Dim xmla1_cnd_name_prefix As XmlText
            Dim xmla1_cnd_name_first As XmlText
            Dim xmla1_cnd_name_middle As XmlText
            Dim xmla1_cnd_name_last As XmlText
            'id------------------------
            'Dim xmla1_cnd_id As XmlText
            Dim xmla1_cnd_id_no As XmlText
            Dim xmla1_cnd_id_type As XmlText
            'location-----------------
            'Dim xmla1_cnd_location As XmlText
            Dim xmla1_cnd_location_addr As XmlText
            Dim xmla1_cnd_location_phone As XmlText
            Dim xmla1_cnd_location_fax As XmlText
            'office-----------------
            'Dim xmla1_cnd_office As XmlText
            Dim xmla1_cnd_office_occ As XmlText
            Dim xmla1_cnd_office_desc As XmlText
            Dim xmla1_cnd_office_org As XmlText
            Dim xmla1_cnd_office_phone As XmlText
            Dim xmla1_cnd_office_fax As XmlText
            'contact----------------
            'Dim xmla1_cnd_contact As XmlText
            Dim xmla1_cnd_contact_addr As XmlText
            Dim xmla1_cnd_contact_phone As XmlText
            Dim xmla1_cnd_contact_fax As XmlText
            'iddoc----------------
            'Dim xmla1_cnd_iddoc As XmlText
            Dim xmla1_cnd_iddoc_type As XmlText
            Dim xmla1_cnd_iddoc_desc As XmlText
            Dim xmla1_cnd_iddoc_no As XmlText
            Dim xmla1_cnd_iddoc_by As XmlText
            Dim xmla1_cnd_iddoc_date As XmlText
            Dim xmla1_cnd_iddoc_expire As XmlText
            'cnd==========End==================
            'psn==========Begin==================
            'Dim xmla1_psn As XmlText
            Dim xmla1_psn_relation(pCountPsn) As XmlText
            'name-------------------
            'Dim xmla1_psn_name As XmlText
            Dim xmla1_psn_name_prefix(pCountPsn) As XmlText
            Dim xmla1_psn_name_first(pCountPsn) As XmlText
            Dim xmla1_psn_name_middle(pCountPsn) As XmlText
            Dim xmla1_psn_name_last(pCountPsn) As XmlText
            'id------------------------
            'Dim xmla1_psn_id As XmlText
            Dim xmla1_psn_id_no(pCountPsn) As XmlText
            Dim xmla1_psn_id_type(pCountPsn) As XmlText
            'location-----------------
            'Dim xmla1_psn_location As XmlText
            Dim xmla1_psn_location_addr(pCountPsn) As XmlText
            Dim xmla1_psn_location_phone(pCountPsn) As XmlText
            Dim xmla1_psn_location_fax(pCountPsn) As XmlText
            'office-----------------
            'Dim xmla1_psn_office As XmlText
            Dim xmla1_psn_office_occ(pCountPsn) As XmlText
            Dim xmla1_psn_office_org(pCountPsn) As XmlText
            Dim xmla1_psn_office_phone(pCountPsn) As XmlText
            Dim xmla1_psn_office_fax(pCountPsn) As XmlText
            Dim xmla1_psn_office_type(pCountPsn) As XmlText
            Dim xmla1_psn_office_desc(pCountPsn) As XmlText
            'contact----------------
            'Dim xmla1_psn_contact As XmlText
            Dim xmla1_psn_contact_addr(pCountPsn) As XmlText
            Dim xmla1_psn_contact_phone(pCountPsn) As XmlText
            Dim xmla1_psn_contact_fax(pCountPsn) As XmlText
            'iddoc----------------
            'Dim xmla1_psn_iddoc As XmlText
            Dim xmla1_psn_iddoc_type(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_desc(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_no(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_by(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_date(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_expire(pCountPsn) As XmlText
            'psn==========End==================

            'tsc==========Begin==================
            'Dim xmla1_tsc As XmlText
            Dim xmla1_tsc_date As XmlText
            'contact----------------
            'Dim xmla1_tsc_item As XmlText
            Dim xmla1_tsc_item_type As XmlText
            Dim xmla1_tsc_item_desc As XmlText
            Dim xmla1_tsc_item_accno As XmlText
            'Dim xmla1_tsc_item_cur As XmlText
            Dim xmla1_tsc_item_amt As XmlText
            'name-------------------
            'Dim xmla1_tsc_name As XmlText
            Dim xmla1_tsc_name_prefix As XmlText
            Dim xmla1_tsc_name_first As XmlText
            Dim xmla1_tsc_name_middle As XmlText
            Dim xmla1_tsc_name_last As XmlText
            'obj----------------
            'Dim xmla1_tsc_obj As XmlText
            Dim xmla1_tsc_obj_type As XmlText
            Dim xmla1_tsc_obj_desc As XmlText
            'tsc==========End==================
            'record==========Begin==================
            'Dim xmla1_record As XmlText
            Dim xmla1_record_writer As XmlText
            Dim xmla1_record_sign As XmlText
            Dim xmla1_record_date As XmlText
            'record==========End==================

            xmla1_type = xmldoc.CreateTextNode(pAmlo1Data.p01_type)
            xmla1_reportid = xmldoc.CreateTextNode(pAmlo1Data.p02_reportid)
            xmla1_revision = xmldoc.CreateTextNode(pAmlo1Data.p03_revision)
            xmla1_date = xmldoc.CreateTextNode(pAmlo1Data.p04_date)
            'cnd==========Begin================== 
            'name------------------- 
            xmla1_cnd_name_prefix = xmldoc.CreateTextNode(pAmlo1Data.p101_cnd_name_prefix)
            xmla1_cnd_name_first = xmldoc.CreateTextNode(pAmlo1Data.p102_cnd_name_first)
            xmla1_cnd_name_middle = xmldoc.CreateTextNode(pAmlo1Data.p103_cnd_name_middle)
            xmla1_cnd_name_last = xmldoc.CreateTextNode(pAmlo1Data.p104_cnd_name_last)
            'id------------------------ 
            xmla1_cnd_id_no = xmldoc.CreateTextNode(pAmlo1Data.p105_cnd_id_no)
            xmla1_cnd_id_type = xmldoc.CreateTextNode(pAmlo1Data.p106_cnd_id_type)
            'location----------------- 
            xmla1_cnd_location_addr = xmldoc.CreateTextNode(pAmlo1Data.p107_cnd_location_addr)
            xmla1_cnd_location_phone = xmldoc.CreateTextNode(pAmlo1Data.p108_cnd_location_phone)
            xmla1_cnd_location_fax = xmldoc.CreateTextNode(pAmlo1Data.p109_cnd_location_fax)
            'office----------------- 
            xmla1_cnd_office_occ = xmldoc.CreateTextNode(pAmlo1Data.p110_cnd_office_occ)
            xmla1_cnd_office_desc = xmldoc.CreateTextNode(pAmlo1Data.p111_cnd_office_desc)
            xmla1_cnd_office_org = xmldoc.CreateTextNode(pAmlo1Data.p112_cnd_office_org)
            xmla1_cnd_office_phone = xmldoc.CreateTextNode(pAmlo1Data.p113_cnd_office_phone)
            xmla1_cnd_office_fax = xmldoc.CreateTextNode(pAmlo1Data.p114_cnd_office_fax)
            'contact---------------- 
            xmla1_cnd_contact_addr = xmldoc.CreateTextNode(pAmlo1Data.p115_cnd_contact_addr)
            xmla1_cnd_contact_phone = xmldoc.CreateTextNode(pAmlo1Data.p116_cnd_contact_phone)
            xmla1_cnd_contact_fax = xmldoc.CreateTextNode(pAmlo1Data.p117_cnd_contact_fax)
            'iddoc---------------- 
            xmla1_cnd_iddoc_type = xmldoc.CreateTextNode(pAmlo1Data.p118_cnd_iddoc_type)
            xmla1_cnd_iddoc_desc = xmldoc.CreateTextNode(pAmlo1Data.p119_cnd_iddoc_desc)
            xmla1_cnd_iddoc_no = xmldoc.CreateTextNode(pAmlo1Data.p120_cnd_iddoc_no)
            xmla1_cnd_iddoc_by = xmldoc.CreateTextNode(pAmlo1Data.p121_cnd_iddoc_by)
            xmla1_cnd_iddoc_date = xmldoc.CreateTextNode(pAmlo1Data.p122_cnd_iddoc_date)
            xmla1_cnd_iddoc_expire = xmldoc.CreateTextNode(pAmlo1Data.p123_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin================== 
                xmla1_psn_relation(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p201_psn_relation)
                'name------------------- 
                xmla1_psn_name_prefix(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p202_psn_name_prefix)
                xmla1_psn_name_first(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p203_psn_name_first)
                xmla1_psn_name_middle(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p204_psn_name_middle)
                xmla1_psn_name_last(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p205_psn_name_last)
                'id------------------------ 
                xmla1_psn_id_no(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p206_psn_id_no)
                xmla1_psn_id_type(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p207_psn_id_type)
                'location----------------- 
                xmla1_psn_location_addr(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p208_psn_location_addr)
                xmla1_psn_location_phone(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p209_psn_location_phone)
                xmla1_psn_location_fax(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p210_psn_location_fax)
                'office----------------- 
                xmla1_psn_office_occ(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p211_psn_office_occ)
                xmla1_psn_office_org(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p212_psn_office_org)
                xmla1_psn_office_phone(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p213_psn_office_phone)
                xmla1_psn_office_fax(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p214_psn_office_fax)
                xmla1_psn_office_type(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p215_psn_office_type)
                xmla1_psn_office_desc(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p216_psn_office_desc)
                'contact---------------- 
                xmla1_psn_contact_addr(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p217_psn_contact_addr)
                xmla1_psn_contact_phone(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p218_psn_contact_phone)
                xmla1_psn_contact_fax(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p219_psn_contact_fax)
                'iddoc---------------- 
                xmla1_psn_iddoc_type(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p220_psn_iddoc_type)
                xmla1_psn_iddoc_desc(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p221_psn_iddoc_desc)
                xmla1_psn_iddoc_no(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p222_psn_iddoc_no)
                xmla1_psn_iddoc_by(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p223_psn_iddoc_by)
                xmla1_psn_iddoc_date(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p224_psn_iddoc_date)
                xmla1_psn_iddoc_expire(i) = xmldoc.CreateTextNode(pAmlo1Psn(i).p225_psn_iddoc_expire)
                'psn==========End==================
            Next i
            'tsc==========Begin================== 
            xmla1_tsc_date = xmldoc.CreateTextNode(pAmlo1Data.p301_tsc_date)
            'contact---------------- 
            xmla1_tsc_item_type = xmldoc.CreateTextNode(pAmlo1Data.p302_tsc_item_type)
            xmla1_tsc_item_desc = xmldoc.CreateTextNode(pAmlo1Data.p303_tsc_item_desc)
            xmla1_tsc_item_accno = xmldoc.CreateTextNode(pAmlo1Data.p304_tsc_item_acccno)
            'xmla1_tsc_item_cur = xmldoc.CreateTextNode(pAmlo1Data.p305_tsc_item_cur)
            xmla1_tsc_item_amt = xmldoc.CreateTextNode(pAmlo1Data.p306_tsc_item_amt)
            'name------------------- 
            xmla1_tsc_name_prefix = xmldoc.CreateTextNode(pAmlo1Data.p307_tsc_name_prefix)
            xmla1_tsc_name_first = xmldoc.CreateTextNode(pAmlo1Data.p308_tsc_name_first)
            xmla1_tsc_name_middle = xmldoc.CreateTextNode(pAmlo1Data.p309_tsc_name_middle)
            xmla1_tsc_name_last = xmldoc.CreateTextNode(pAmlo1Data.p310_tsc_name_last)
            'obj---------------- 
            xmla1_tsc_obj_type = xmldoc.CreateTextNode(pAmlo1Data.p311_tsc_obj_type)
            xmla1_tsc_obj_desc = xmldoc.CreateTextNode(pAmlo1Data.p312_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            xmla1_record_writer = xmldoc.CreateTextNode(pAmlo1Data.p401_record_writer)
            xmla1_record_sign = xmldoc.CreateTextNode(pAmlo1Data.p402_record_sign)
            xmla1_record_date = xmldoc.CreateTextNode(pAmlo1Data.p403_record_date)
            'record==========End==================

            '// append the nodes to the parentNode without the value
            parentNode.AppendChild(a1_type)
            parentNode.AppendChild(a1_reportid)
            parentNode.AppendChild(a1_revision)
            parentNode.AppendChild(a1_date)
            'cnd==========Begin==================
            parentNode.AppendChild(a1_cnd)
            'name-------------------
            a1_cnd.AppendChild(a1_cnd_name)
            a1_cnd_name.AppendChild(a1_cnd_name_prefix)
            a1_cnd_name.AppendChild(a1_cnd_name_first)
            a1_cnd_name.AppendChild(a1_cnd_name_middle)
            a1_cnd_name.AppendChild(a1_cnd_name_last)
            'id------------------------
            a1_cnd.AppendChild(a1_cnd_id)
            a1_cnd_id.AppendChild(a1_cnd_id_no)
            a1_cnd_id.AppendChild(a1_cnd_id_type)
            'location-----------------
            a1_cnd.AppendChild(a1_cnd_location)
            a1_cnd_location.AppendChild(a1_cnd_location_addr)
            a1_cnd_location.AppendChild(a1_cnd_location_phone)
            a1_cnd_location.AppendChild(a1_cnd_location_fax)
            'office-----------------
            a1_cnd.AppendChild(a1_cnd_office)
            a1_cnd_office.AppendChild(a1_cnd_office_occ)
            a1_cnd_office.AppendChild(a1_cnd_office_desc)
            a1_cnd_office.AppendChild(a1_cnd_office_org)
            a1_cnd_office.AppendChild(a1_cnd_office_phone)
            a1_cnd_office.AppendChild(a1_cnd_office_fax)
            'contact----------------
            a1_cnd.AppendChild(a1_cnd_contact)
            a1_cnd_contact.AppendChild(a1_cnd_contact_addr)
            a1_cnd_contact.AppendChild(a1_cnd_contact_phone)
            a1_cnd_contact.AppendChild(a1_cnd_contact_fax)
            'iddoc----------------
            a1_cnd.AppendChild(a1_cnd_iddoc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_type)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_desc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_no)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_by)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_date)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin==================
                parentNode.AppendChild(a1_psn(i))
                a1_psn(i).AppendChild(a1_psn_relation(i))
                'name-------------------
                a1_psn(i).AppendChild(a1_psn_name(i))
                a1_psn_name(i).AppendChild(a1_psn_name_prefix(i))
                a1_psn_name(i).AppendChild(a1_psn_name_first(i))
                a1_psn_name(i).AppendChild(a1_psn_name_middle(i))
                a1_psn_name(i).AppendChild(a1_psn_name_last(i))
                'id------------------------
                a1_psn(i).AppendChild(a1_psn_id(i))
                a1_psn_id(i).AppendChild(a1_psn_id_no(i))
                a1_psn_id(i).AppendChild(a1_psn_id_type(i))
                'location-----------------
                a1_psn(i).AppendChild(a1_psn_location(i))
                a1_psn_location(i).AppendChild(a1_psn_location_addr(i))
                a1_psn_location(i).AppendChild(a1_psn_location_phone(i))
                a1_psn_location(i).AppendChild(a1_psn_location_fax(i))
                'office-----------------
                a1_psn(i).AppendChild(a1_psn_office(i))
                a1_psn_office(i).AppendChild(a1_psn_office_occ(i))
                a1_psn_office(i).AppendChild(a1_psn_office_org(i))
                a1_psn_office(i).AppendChild(a1_psn_office_phone(i))
                a1_psn_office(i).AppendChild(a1_psn_office_fax(i))
                a1_psn_office(i).AppendChild(a1_psn_office_type(i))
                a1_psn_office(i).AppendChild(a1_psn_office_desc(i))
                'contact----------------
                a1_psn(i).AppendChild(a1_psn_contact(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_addr(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_phone(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_fax(i))
                'iddoc----------------
                a1_psn(i).AppendChild(a1_psn_iddoc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_type(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_desc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_no(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_by(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_date(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_expire(i))
                'psn==========End==================

            Next

            'tsc==========Begin==================
            parentNode.AppendChild(a1_tsc)
            a1_tsc.AppendChild(a1_tsc_date)
            'contact----------------
            a1_tsc.AppendChild(a1_tsc_item)
            a1_tsc_item.AppendChild(a1_tsc_item_type)
            a1_tsc_item.AppendChild(a1_tsc_item_desc)
            a1_tsc_item.AppendChild(a1_tsc_item_accno)
            'a1_tsc_item.AppendChild(a1_tsc_item_cur)
            a1_tsc_item.AppendChild(a1_tsc_item_amt)
            'name-------------------
            a1_tsc.AppendChild(a1_tsc_name)
            a1_tsc_name.AppendChild(a1_tsc_name_prefix)
            a1_tsc_name.AppendChild(a1_tsc_name_first)
            a1_tsc_name.AppendChild(a1_tsc_name_middle)
            a1_tsc_name.AppendChild(a1_tsc_name_last)
            'obj----------------
            a1_tsc.AppendChild(a1_tsc_obj)
            a1_tsc_obj.AppendChild(a1_tsc_obj_type)
            a1_tsc_obj.AppendChild(a1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin==================
            parentNode.AppendChild(a1_record)
            a1_record.AppendChild(a1_record_writer)
            a1_record.AppendChild(a1_record_sign)
            a1_record.AppendChild(a1_record_date)
            'record==========End==================

            '// save the value of the fields into the nodes 
            a1_type.AppendChild(xmla1_type)
            a1_reportid.AppendChild(xmla1_reportid)
            a1_revision.AppendChild(xmla1_revision)
            a1_date.AppendChild(xmla1_date)
            'cnd==========Begin================== 
            'name-------------------
            'a1_cnd_name.AppendChild(xmla1_cnd_name)
            a1_cnd_name_prefix.AppendChild(xmla1_cnd_name_prefix)
            a1_cnd_name_first.AppendChild(xmla1_cnd_name_first)
            a1_cnd_name_middle.AppendChild(xmla1_cnd_name_middle)
            a1_cnd_name_last.AppendChild(xmla1_cnd_name_last)
            'id------------------------  
            a1_cnd_id_no.AppendChild(xmla1_cnd_id_no)
            a1_cnd_id_type.AppendChild(xmla1_cnd_id_type)
            'location----------------- 
            a1_cnd_location_addr.AppendChild(xmla1_cnd_location_addr)
            a1_cnd_location_phone.AppendChild(xmla1_cnd_location_phone)
            a1_cnd_location_fax.AppendChild(xmla1_cnd_location_fax)
            'office----------------- 
            a1_cnd_office_occ.AppendChild(xmla1_cnd_office_occ)
            a1_cnd_office_desc.AppendChild(xmla1_cnd_office_desc)
            a1_cnd_office_org.AppendChild(xmla1_cnd_office_org)
            a1_cnd_office_phone.AppendChild(xmla1_cnd_office_phone)
            a1_cnd_office_fax.AppendChild(xmla1_cnd_office_fax)
            'contact---------------- 
            a1_cnd_contact_addr.AppendChild(xmla1_cnd_contact_addr)
            a1_cnd_contact_phone.AppendChild(xmla1_cnd_contact_phone)
            a1_cnd_contact_fax.AppendChild(xmla1_cnd_contact_fax)
            'iddoc---------------- 
            a1_cnd_iddoc_type.AppendChild(xmla1_cnd_iddoc_type)
            a1_cnd_iddoc_desc.AppendChild(xmla1_cnd_iddoc_desc)
            a1_cnd_iddoc_no.AppendChild(xmla1_cnd_iddoc_no)
            a1_cnd_iddoc_by.AppendChild(xmla1_cnd_iddoc_by)
            a1_cnd_iddoc_date.AppendChild(xmla1_cnd_iddoc_date)
            a1_cnd_iddoc_expire.AppendChild(xmla1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                a1_psn_relation(i).AppendChild(xmla1_psn_relation(i))
                'name------------------- 
                a1_psn_name_prefix(i).AppendChild(xmla1_psn_name_prefix(i))
                a1_psn_name_first(i).AppendChild(xmla1_psn_name_first(i))
                a1_psn_name_middle(i).AppendChild(xmla1_psn_name_middle(i))
                a1_psn_name_last(i).AppendChild(xmla1_psn_name_last(i))
                'id------------------------ 
                a1_psn_id_no(i).AppendChild(xmla1_psn_id_no(i))
                a1_psn_id_type(i).AppendChild(xmla1_psn_id_type(i))
                'location----------------- 
                a1_psn_location_addr(i).AppendChild(xmla1_psn_location_addr(i))
                a1_psn_location_phone(i).AppendChild(xmla1_psn_location_phone(i))
                a1_psn_location_fax(i).AppendChild(xmla1_psn_location_fax(i))
                'office----------------- 
                a1_psn_office_occ(i).AppendChild(xmla1_psn_office_occ(i))
                a1_psn_office_org(i).AppendChild(xmla1_psn_office_org(i))
                a1_psn_office_phone(i).AppendChild(xmla1_psn_office_phone(i))
                a1_psn_office_fax(i).AppendChild(xmla1_psn_office_fax(i))
                a1_psn_office_type(i).AppendChild(xmla1_psn_office_type(i))
                a1_psn_office_desc(i).AppendChild(xmla1_psn_office_desc(i))
                'contact---------------- 
                a1_psn_contact_addr(i).AppendChild(xmla1_psn_contact_addr(i))
                a1_psn_contact_phone(i).AppendChild(xmla1_psn_contact_phone(i))
                a1_psn_contact_fax(i).AppendChild(xmla1_psn_contact_fax(i))
                'iddoc---------------- 
                a1_psn_iddoc_type(i).AppendChild(xmla1_psn_iddoc_type(i))
                a1_psn_iddoc_desc(i).AppendChild(xmla1_psn_iddoc_desc(i))
                a1_psn_iddoc_no(i).AppendChild(xmla1_psn_iddoc_no(i))
                a1_psn_iddoc_by(i).AppendChild(xmla1_psn_iddoc_by(i))
                a1_psn_iddoc_date(i).AppendChild(xmla1_psn_iddoc_date(i))
                a1_psn_iddoc_expire(i).AppendChild(xmla1_psn_iddoc_expire(i))
                'psn==========End==================

            Next
            'psn==========Begin================== 

            'tsc==========Begin================== 
            a1_tsc_date.AppendChild(xmla1_tsc_date)
            'contact---------------- 
            a1_tsc_item_type.AppendChild(xmla1_tsc_item_type)
            a1_tsc_item_desc.AppendChild(xmla1_tsc_item_desc)
            a1_tsc_item_accno.AppendChild(xmla1_tsc_item_accno)
            'a1_tsc_item_cur.AppendChild(xmla1_tsc_item_cur)
            a1_tsc_item_amt.AppendChild(xmla1_tsc_item_amt)
            'name------------------- 
            a1_tsc_name_prefix.AppendChild(xmla1_tsc_name_prefix)
            a1_tsc_name_first.AppendChild(xmla1_tsc_name_first)
            a1_tsc_name_middle.AppendChild(xmla1_tsc_name_middle)
            a1_tsc_name_last.AppendChild(xmla1_tsc_name_last)
            'obj---------------- 
            a1_tsc_obj_type.AppendChild(xmla1_tsc_obj_type)
            a1_tsc_obj_desc.AppendChild(xmla1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            a1_record_writer.AppendChild(xmla1_record_writer)
            a1_record_sign.AppendChild(xmla1_record_sign)
            a1_record_date.AppendChild(xmla1_record_date)
            'record==========End==================

            '// Save to the XML file

            'xmldoc.Save(filePath)

            'Dim FileStream As StreamReader = New StreamReader(filePath)
            'Dim fileContent As String = FileStream.ReadToEnd()
            'FileStream.Close()

            ''Dim ansiWriter As StreamWriter = New StreamWriter(filePath.Replace(".xml", "-ansi.xml"), False)
            'Dim ansiWriter As StreamWriter = New StreamWriter(filePath.Replace(".xml", "-ansi.xml"), False, Encoding.GetEncoding(1250))
            Dim ansiWriter As StreamWriter
            ansiWriter = New StreamWriter(filePath, False, Encoding.Default)
            xmldoc.Save(ansiWriter)
            '' ansiWriter.Write(fileContent, Encoding.Default)
            ansiWriter.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function AddAMLO2node(ByVal filePath As String, ByVal pAmlo2Data As clsAmlo2Data, ByVal pCountPsn As Integer, ByVal pAmlo2Psn() As clsAmlo2Psn, ByVal intLoop As Integer, ByVal intMaxLoop As Integer) As Boolean
        Try
            Dim i As Integer
            Dim xmldoc As XmlDocument
            xmldoc = New XmlDocument()
            xmldoc.Load(filePath)
            Dim parentNode As XmlElement
            parentNode = xmldoc.CreateElement("doc")
            Dim a0_version As XmlElement
            Dim a0_org As XmlElement
            Dim xmla0_version As XmlText
            Dim xmla0_org As XmlText
            clsDateFormat = New clsDateFormat

            If Not (IsDBNull(xmldoc.DocumentElement)) Then
                xmldoc.DocumentElement.PrependChild(parentNode)
                If (intLoop = intMaxLoop) Then
                    a0_org = xmldoc.CreateElement("org")
                    a0_version = xmldoc.CreateElement("version")

                    xmla0_org = xmldoc.CreateTextNode("ธนาคารอาคารสงเคราะห์")
                    xmla0_version = xmldoc.CreateTextNode("1.1")

                    xmldoc.DocumentElement.PrependChild(a0_org)
                    xmldoc.DocumentElement.PrependChild(a0_version)

                    a0_org.AppendChild(xmla0_org)
                    a0_version.AppendChild(xmla0_version)

                End If

            End If

            ' Create the required nodes 

            Dim a1_type As XmlElement
            Dim a1_reportid As XmlElement
            Dim a1_revision As XmlElement
            Dim a1_date As XmlElement
            'cnd==========Begin==================
            Dim a1_cnd As XmlElement
            'name-------------------
            Dim a1_cnd_name As XmlElement
            Dim a1_cnd_name_prefix As XmlElement
            Dim a1_cnd_name_first As XmlElement
            Dim a1_cnd_name_middle As XmlElement
            Dim a1_cnd_name_last As XmlElement
            'id------------------------
            Dim a1_cnd_id As XmlElement
            Dim a1_cnd_id_no As XmlElement
            Dim a1_cnd_id_type As XmlElement
            'location-----------------
            Dim a1_cnd_location As XmlElement
            Dim a1_cnd_location_addr As XmlElement
            Dim a1_cnd_location_phone As XmlElement
            Dim a1_cnd_location_fax As XmlElement
            'office-----------------
            Dim a1_cnd_office As XmlElement
            Dim a1_cnd_office_occ As XmlElement
            Dim a1_cnd_office_desc As XmlElement
            Dim a1_cnd_office_org As XmlElement
            Dim a1_cnd_office_phone As XmlElement
            Dim a1_cnd_office_fax As XmlElement
            'contact----------------
            Dim a1_cnd_contact As XmlElement
            Dim a1_cnd_contact_addr As XmlElement
            Dim a1_cnd_contact_phone As XmlElement
            Dim a1_cnd_contact_fax As XmlElement
            'iddoc----------------
            Dim a1_cnd_iddoc As XmlElement
            Dim a1_cnd_iddoc_type As XmlElement
            Dim a1_cnd_iddoc_desc As XmlElement
            Dim a1_cnd_iddoc_no As XmlElement
            Dim a1_cnd_iddoc_by As XmlElement
            Dim a1_cnd_iddoc_date As XmlElement
            Dim a1_cnd_iddoc_expire As XmlElement
            'cnd==========End==================
            'psn==========Begin==================
            Dim a1_psn(pCountPsn) As XmlElement
            Dim a1_psn_relation(pCountPsn) As XmlElement
            'name-------------------
            Dim a1_psn_name(pCountPsn) As XmlElement
            Dim a1_psn_name_prefix(pCountPsn) As XmlElement
            Dim a1_psn_name_first(pCountPsn) As XmlElement
            Dim a1_psn_name_middle(pCountPsn) As XmlElement
            Dim a1_psn_name_last(pCountPsn) As XmlElement
            'id------------------------
            Dim a1_psn_id(pCountPsn) As XmlElement
            Dim a1_psn_id_no(pCountPsn) As XmlElement
            Dim a1_psn_id_type(pCountPsn) As XmlElement
            'location-----------------
            Dim a1_psn_location(pCountPsn) As XmlElement
            Dim a1_psn_location_addr(pCountPsn) As XmlElement
            Dim a1_psn_location_phone(pCountPsn) As XmlElement
            Dim a1_psn_location_fax(pCountPsn) As XmlElement
            'office-----------------
            Dim a1_psn_office(pCountPsn) As XmlElement
            Dim a1_psn_office_occ(pCountPsn) As XmlElement
            Dim a1_psn_office_org(pCountPsn) As XmlElement
            Dim a1_psn_office_phone(pCountPsn) As XmlElement
            Dim a1_psn_office_fax(pCountPsn) As XmlElement
            Dim a1_psn_office_type(pCountPsn) As XmlElement
            Dim a1_psn_office_desc(pCountPsn) As XmlElement
            'contact----------------
            Dim a1_psn_contact(pCountPsn) As XmlElement
            Dim a1_psn_contact_addr(pCountPsn) As XmlElement
            Dim a1_psn_contact_phone(pCountPsn) As XmlElement
            Dim a1_psn_contact_fax(pCountPsn) As XmlElement
            'iddoc----------------
            Dim a1_psn_iddoc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_type(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_desc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_no(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_by(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_date(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_expire(pCountPsn) As XmlElement
            'psn==========End==================

            'tsc==========Begin==================
            Dim a1_tsc As XmlElement
            Dim a1_tsc_date As XmlElement
            Dim a1_tsc_type As XmlElement
            Dim a1_tsc_desc As XmlElement

            'asset---------------- 
            Dim a1_tsc_asset As XmlElement
            Dim a1_tsc_asset_type As XmlElement
            Dim a1_tsc_asset_desc As XmlElement
            Dim a1_tsc_asset_detail As XmlElement
            Dim a1_tsc_asset_amt As XmlElement
            'acc-------------------   
            Dim a1_tsc_acc As XmlElement
            Dim a1_tsc_acc_accno As XmlElement
            Dim a1_tsc_acc_aname As XmlElement
            'acc_name------------------- 
            Dim a1_tsc_acc_name As XmlElement
            Dim a1_tsc_acc_name_prefix As XmlElement
            Dim a1_tsc_acc_name_first As XmlElement
            Dim a1_tsc_acc_name_middle As XmlElement
            Dim a1_tsc_acc_name_last As XmlElement
            'racc---------------- 
            Dim a1_tsc_racc As XmlElement
            Dim a1_tsc_racc_accno As XmlElement
            Dim a1_tsc_racc_aname As XmlElement
            'racc_name------------------- 
            Dim a1_tsc_racc_name As XmlElement
            Dim a1_tsc_racc_name_prefix As XmlElement
            Dim a1_tsc_racc_name_first As XmlElement
            Dim a1_tsc_racc_name_middle As XmlElement
            Dim a1_tsc_racc_name_last As XmlElement
            'racc---------------- 
            Dim a1_tsc_racc_relation As XmlElement
            Dim a1_tsc_racc_relation_type As XmlElement
            Dim a1_tsc_racc_relation_desc As XmlElement
            'name------------------- 
            Dim a1_tsc_name As XmlElement
            Dim a1_tsc_name_prefix As XmlElement
            Dim a1_tsc_name_first As XmlElement
            Dim a1_tsc_name_middle As XmlElement
            Dim a1_tsc_name_last As XmlElement
            'obj------------------- 
            Dim a1_tsc_obj As XmlElement
            Dim a1_tsc_obj_type As XmlElement
            Dim a1_tsc_obj_desc As XmlElement

            'tsc==========End==================
            'record==========Begin==================
            Dim a1_record As XmlElement
            Dim a1_record_writer As XmlElement
            Dim a1_record_sign As XmlElement
            Dim a1_record_date As XmlElement
            'record==========End==================



            a1_type = xmldoc.CreateElement("type")
            a1_reportid = xmldoc.CreateElement("reportid")
            a1_revision = xmldoc.CreateElement("revision")
            a1_date = xmldoc.CreateElement("date")
            'cnd==========Begin==================
            a1_cnd = xmldoc.CreateElement("cnd")
            'name-------------------
            a1_cnd_name = xmldoc.CreateElement("name")
            a1_cnd_name_prefix = xmldoc.CreateElement("prefix")
            a1_cnd_name_first = xmldoc.CreateElement("first")
            a1_cnd_name_middle = xmldoc.CreateElement("middle")
            a1_cnd_name_last = xmldoc.CreateElement("last")
            'id------------------------
            a1_cnd_id = xmldoc.CreateElement("id")
            a1_cnd_id_no = xmldoc.CreateElement("no")
            a1_cnd_id_type = xmldoc.CreateElement("type")
            'location-----------------
            a1_cnd_location = xmldoc.CreateElement("location")
            a1_cnd_location_addr = xmldoc.CreateElement("addr")
            a1_cnd_location_phone = xmldoc.CreateElement("phone")
            a1_cnd_location_fax = xmldoc.CreateElement("fax")
            'office-----------------
            a1_cnd_office = xmldoc.CreateElement("office")
            a1_cnd_office_occ = xmldoc.CreateElement("occ")
            a1_cnd_office_desc = xmldoc.CreateElement("desc")
            a1_cnd_office_org = xmldoc.CreateElement("org")
            a1_cnd_office_phone = xmldoc.CreateElement("phone")
            a1_cnd_office_fax = xmldoc.CreateElement("fax")
            'contact----------------
            a1_cnd_contact = xmldoc.CreateElement("contact")
            a1_cnd_contact_addr = xmldoc.CreateElement("addr")
            a1_cnd_contact_phone = xmldoc.CreateElement("phone")
            a1_cnd_contact_fax = xmldoc.CreateElement("fax")
            'iddoc----------------
            a1_cnd_iddoc = xmldoc.CreateElement("iddoc")
            a1_cnd_iddoc_type = xmldoc.CreateElement("type")
            a1_cnd_iddoc_desc = xmldoc.CreateElement("desc")
            a1_cnd_iddoc_no = xmldoc.CreateElement("no")
            a1_cnd_iddoc_by = xmldoc.CreateElement("by")
            a1_cnd_iddoc_date = xmldoc.CreateElement("date")
            a1_cnd_iddoc_expire = xmldoc.CreateElement("expire")
            'cnd==========End==================

            For i = 1 To pCountPsn
                'psn==========Begin==================
                a1_psn(i) = xmldoc.CreateElement("psn")
                a1_psn_relation(i) = xmldoc.CreateElement("relation")
                'name-------------------
                a1_psn_name(i) = xmldoc.CreateElement("name")
                a1_psn_name_prefix(i) = xmldoc.CreateElement("prefix")
                a1_psn_name_first(i) = xmldoc.CreateElement("first")
                a1_psn_name_middle(i) = xmldoc.CreateElement("middle")
                a1_psn_name_last(i) = xmldoc.CreateElement("last")
                'id------------------------
                a1_psn_id(i) = xmldoc.CreateElement("id")
                a1_psn_id_no(i) = xmldoc.CreateElement("no")
                a1_psn_id_type(i) = xmldoc.CreateElement("type")
                'location-----------------
                a1_psn_location(i) = xmldoc.CreateElement("location")
                a1_psn_location_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_location_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_location_fax(i) = xmldoc.CreateElement("fax")
                'office-----------------
                a1_psn_office(i) = xmldoc.CreateElement("office")
                a1_psn_office_occ(i) = xmldoc.CreateElement("occ")
                a1_psn_office_org(i) = xmldoc.CreateElement("org")
                a1_psn_office_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_office_fax(i) = xmldoc.CreateElement("fax")
                a1_psn_office_type(i) = xmldoc.CreateElement("type")
                a1_psn_office_desc(i) = xmldoc.CreateElement("desc")
                'contact----------------
                a1_psn_contact(i) = xmldoc.CreateElement("contact")
                a1_psn_contact_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_contact_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_contact_fax(i) = xmldoc.CreateElement("fax")
                'iddoc----------------
                a1_psn_iddoc(i) = xmldoc.CreateElement("iddoc")
                a1_psn_iddoc_type(i) = xmldoc.CreateElement("type")
                a1_psn_iddoc_desc(i) = xmldoc.CreateElement("desc")
                a1_psn_iddoc_no(i) = xmldoc.CreateElement("no")
                a1_psn_iddoc_by(i) = xmldoc.CreateElement("by")
                a1_psn_iddoc_date(i) = xmldoc.CreateElement("date")
                a1_psn_iddoc_expire(i) = xmldoc.CreateElement("expire")
                'psn==========End==================
            Next


            'tsc==========Begin==================
            a1_tsc = xmldoc.CreateElement("tsc")
            a1_tsc_date = xmldoc.CreateElement("date")
            a1_tsc_type = xmldoc.CreateElement("type")
            a1_tsc_desc = xmldoc.CreateElement("desc")

            'asset---------------- 
            a1_tsc_asset = xmldoc.CreateElement("asset")
            a1_tsc_asset_type = xmldoc.CreateElement("type")
            a1_tsc_asset_desc = xmldoc.CreateElement("desc")
            a1_tsc_asset_detail = xmldoc.CreateElement("detail")
            a1_tsc_asset_amt = xmldoc.CreateElement("amt")

            'acc-------------------   
            a1_tsc_acc = xmldoc.CreateElement("acc")
            a1_tsc_acc_accno = xmldoc.CreateElement("accno")
            a1_tsc_acc_aname = xmldoc.CreateElement("aname")
            'acc_name------------------- 
            a1_tsc_acc_name = xmldoc.CreateElement("name")
            a1_tsc_acc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_acc_name_first = xmldoc.CreateElement("first")
            a1_tsc_acc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_acc_name_last = xmldoc.CreateElement("last")
            'racc---------------- 
            a1_tsc_racc = xmldoc.CreateElement("racc")
            a1_tsc_racc_accno = xmldoc.CreateElement("accno")
            a1_tsc_racc_aname = xmldoc.CreateElement("aname")
            'racc_name------------------- 
            a1_tsc_racc_name = xmldoc.CreateElement("name")
            a1_tsc_racc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_racc_name_first = xmldoc.CreateElement("first")
            a1_tsc_racc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_racc_name_last = xmldoc.CreateElement("last")
            'racc---------------- 
            a1_tsc_racc_relation = xmldoc.CreateElement("relation")
            a1_tsc_racc_relation_type = xmldoc.CreateElement("type")
            a1_tsc_racc_relation_desc = xmldoc.CreateElement("desc")
            'name------------------- 
            a1_tsc_name = xmldoc.CreateElement("name")
            a1_tsc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_name_first = xmldoc.CreateElement("first")
            a1_tsc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_name_last = xmldoc.CreateElement("last")
            'obj------------------- 
            a1_tsc_obj = xmldoc.CreateElement("obj")
            a1_tsc_obj_type = xmldoc.CreateElement("type")
            a1_tsc_obj_desc = xmldoc.CreateElement("desc")


            'tsc==========End==================
            'record==========Begin==================
            a1_record = xmldoc.CreateElement("record")
            a1_record_writer = xmldoc.CreateElement("writer")
            a1_record_sign = xmldoc.CreateElement("sign")
            a1_record_date = xmldoc.CreateElement("date")
            'record==========End==================

            Dim xmla1_type As XmlText
            Dim xmla1_reportid As XmlText
            Dim xmla1_revision As XmlText
            Dim xmla1_date As XmlText
            'cnd==========Begin==================
            ' Dim xmla1_cnd As XmlText
            'name-------------------
            'Dim xmla1_cnd_name As XmlText
            Dim xmla1_cnd_name_prefix As XmlText
            Dim xmla1_cnd_name_first As XmlText
            Dim xmla1_cnd_name_middle As XmlText
            Dim xmla1_cnd_name_last As XmlText
            'id------------------------
            'Dim xmla1_cnd_id As XmlText
            Dim xmla1_cnd_id_no As XmlText
            Dim xmla1_cnd_id_type As XmlText
            'location-----------------
            'Dim xmla1_cnd_location As XmlText
            Dim xmla1_cnd_location_addr As XmlText
            Dim xmla1_cnd_location_phone As XmlText
            Dim xmla1_cnd_location_fax As XmlText
            'office-----------------
            'Dim xmla1_cnd_office As XmlText
            Dim xmla1_cnd_office_occ As XmlText
            Dim xmla1_cnd_office_desc As XmlText
            Dim xmla1_cnd_office_org As XmlText
            Dim xmla1_cnd_office_phone As XmlText
            Dim xmla1_cnd_office_fax As XmlText
            'contact----------------
            'Dim xmla1_cnd_contact As XmlText
            Dim xmla1_cnd_contact_addr As XmlText
            Dim xmla1_cnd_contact_phone As XmlText
            Dim xmla1_cnd_contact_fax As XmlText
            'iddoc----------------
            'Dim xmla1_cnd_iddoc As XmlText
            Dim xmla1_cnd_iddoc_type As XmlText
            Dim xmla1_cnd_iddoc_desc As XmlText
            Dim xmla1_cnd_iddoc_no As XmlText
            Dim xmla1_cnd_iddoc_by As XmlText
            Dim xmla1_cnd_iddoc_date As XmlText
            Dim xmla1_cnd_iddoc_expire As XmlText
            'cnd==========End==================
            'psn==========Begin==================
            'Dim xmla1_psn As XmlText
            Dim xmla1_psn_relation(pCountPsn) As XmlText
            'name-------------------
            'Dim xmla1_psn_name As XmlText
            Dim xmla1_psn_name_prefix(pCountPsn) As XmlText
            Dim xmla1_psn_name_first(pCountPsn) As XmlText
            Dim xmla1_psn_name_middle(pCountPsn) As XmlText
            Dim xmla1_psn_name_last(pCountPsn) As XmlText
            'id------------------------
            'Dim xmla1_psn_id As XmlText
            Dim xmla1_psn_id_no(pCountPsn) As XmlText
            Dim xmla1_psn_id_type(pCountPsn) As XmlText
            'location-----------------
            'Dim xmla1_psn_location As XmlText
            Dim xmla1_psn_location_addr(pCountPsn) As XmlText
            Dim xmla1_psn_location_phone(pCountPsn) As XmlText
            Dim xmla1_psn_location_fax(pCountPsn) As XmlText
            'office-----------------
            'Dim xmla1_psn_office As XmlText
            Dim xmla1_psn_office_occ(pCountPsn) As XmlText
            Dim xmla1_psn_office_org(pCountPsn) As XmlText
            Dim xmla1_psn_office_phone(pCountPsn) As XmlText
            Dim xmla1_psn_office_fax(pCountPsn) As XmlText
            Dim xmla1_psn_office_type(pCountPsn) As XmlText
            Dim xmla1_psn_office_desc(pCountPsn) As XmlText
            'contact----------------
            'Dim xmla1_psn_contact As XmlText
            Dim xmla1_psn_contact_addr(pCountPsn) As XmlText
            Dim xmla1_psn_contact_phone(pCountPsn) As XmlText
            Dim xmla1_psn_contact_fax(pCountPsn) As XmlText
            'iddoc----------------
            'Dim xmla1_psn_iddoc As XmlText
            Dim xmla1_psn_iddoc_type(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_desc(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_no(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_by(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_date(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_expire(pCountPsn) As XmlText
            'psn==========End==================

            'tsc==========Begin==================
            'Dim xmla1_tsc As XmlText
            Dim xmla1_tsc_date As XmlText
            Dim xmla1_tsc_type As XmlText
            Dim xmla1_tsc_desc As XmlText

            'asset----------------  
            Dim xmla1_tsc_asset_type As XmlText
            Dim xmla1_tsc_asset_desc As XmlText
            Dim xmla1_tsc_asset_detail As XmlText
            Dim xmla1_tsc_asset_amt As XmlText

            'acc-------------------   

            Dim xmla1_tsc_acc_accno As XmlText
            Dim xmla1_tsc_acc_aname As XmlText
            'acc_name------------------- 

            Dim xmla1_tsc_acc_name_prefix As XmlText
            Dim xmla1_tsc_acc_name_first As XmlText
            Dim xmla1_tsc_acc_name_middle As XmlText
            Dim xmla1_tsc_acc_name_last As XmlText

            'racc---------------- 

            Dim xmla1_tsc_racc_accno As XmlText
            Dim xmla1_tsc_racc_aname As XmlText
            'racc_name------------------- 

            Dim xmla1_tsc_racc_name_prefix As XmlText
            Dim xmla1_tsc_racc_name_first As XmlText
            Dim xmla1_tsc_racc_name_middle As XmlText
            Dim xmla1_tsc_racc_name_last As XmlText
            'racc---------------- 

            Dim xmla1_tsc_racc_relation_type As XmlText
            Dim xmla1_tsc_racc_relation_desc As XmlText


            'name-------------------
            'Dim xmla1_tsc_name As XmlText
            Dim xmla1_tsc_name_prefix As XmlText
            Dim xmla1_tsc_name_first As XmlText
            Dim xmla1_tsc_name_middle As XmlText
            Dim xmla1_tsc_name_last As XmlText
            'obj----------------
            'Dim xmla1_tsc_obj As XmlText
            Dim xmla1_tsc_obj_type As XmlText
            Dim xmla1_tsc_obj_desc As XmlText
            'tsc==========End==================
            'record==========Begin==================
            'Dim xmla1_record As XmlText
            Dim xmla1_record_writer As XmlText
            Dim xmla1_record_sign As XmlText
            Dim xmla1_record_date As XmlText
            'record==========End==================

            xmla1_type = xmldoc.CreateTextNode(pAmlo2Data.p01_type)
            xmla1_reportid = xmldoc.CreateTextNode(pAmlo2Data.p02_reportid)
            xmla1_revision = xmldoc.CreateTextNode(pAmlo2Data.p03_revision)
            xmla1_date = xmldoc.CreateTextNode(pAmlo2Data.p04_date)
            'cnd==========Begin================== 
            'name------------------- 
            xmla1_cnd_name_prefix = xmldoc.CreateTextNode(pAmlo2Data.p101_cnd_name_prefix)
            xmla1_cnd_name_first = xmldoc.CreateTextNode(pAmlo2Data.p102_cnd_name_first)
            xmla1_cnd_name_middle = xmldoc.CreateTextNode(pAmlo2Data.p103_cnd_name_middle)
            xmla1_cnd_name_last = xmldoc.CreateTextNode(pAmlo2Data.p104_cnd_name_last)
            'id------------------------ 
            xmla1_cnd_id_no = xmldoc.CreateTextNode(pAmlo2Data.p105_cnd_id_no)
            xmla1_cnd_id_type = xmldoc.CreateTextNode(pAmlo2Data.p106_cnd_id_type)
            'location----------------- 
            xmla1_cnd_location_addr = xmldoc.CreateTextNode(pAmlo2Data.p107_cnd_location_addr)
            xmla1_cnd_location_phone = xmldoc.CreateTextNode(pAmlo2Data.p108_cnd_location_phone)
            xmla1_cnd_location_fax = xmldoc.CreateTextNode(pAmlo2Data.p109_cnd_location_fax)
            'office----------------- 
            xmla1_cnd_office_occ = xmldoc.CreateTextNode(pAmlo2Data.p110_cnd_office_occ)
            xmla1_cnd_office_desc = xmldoc.CreateTextNode(pAmlo2Data.p111_cnd_office_desc)
            xmla1_cnd_office_org = xmldoc.CreateTextNode(pAmlo2Data.p112_cnd_office_org)
            xmla1_cnd_office_phone = xmldoc.CreateTextNode(pAmlo2Data.p113_cnd_office_phone)
            xmla1_cnd_office_fax = xmldoc.CreateTextNode(pAmlo2Data.p114_cnd_office_fax)
            'contact---------------- 
            xmla1_cnd_contact_addr = xmldoc.CreateTextNode(pAmlo2Data.p115_cnd_contact_addr)
            xmla1_cnd_contact_phone = xmldoc.CreateTextNode(pAmlo2Data.p116_cnd_contact_phone)
            xmla1_cnd_contact_fax = xmldoc.CreateTextNode(pAmlo2Data.p117_cnd_contact_fax)
            'iddoc---------------- 
            xmla1_cnd_iddoc_type = xmldoc.CreateTextNode(pAmlo2Data.p118_cnd_iddoc_type)
            xmla1_cnd_iddoc_desc = xmldoc.CreateTextNode(pAmlo2Data.p119_cnd_iddoc_desc)
            xmla1_cnd_iddoc_no = xmldoc.CreateTextNode(pAmlo2Data.p120_cnd_iddoc_no)
            xmla1_cnd_iddoc_by = xmldoc.CreateTextNode(pAmlo2Data.p121_cnd_iddoc_by)
            xmla1_cnd_iddoc_date = xmldoc.CreateTextNode(pAmlo2Data.p122_cnd_iddoc_date)
            xmla1_cnd_iddoc_expire = xmldoc.CreateTextNode(pAmlo2Data.p123_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin================== 
                xmla1_psn_relation(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p201_psn_relation)
                'name------------------- 
                xmla1_psn_name_prefix(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p202_psn_name_prefix)
                xmla1_psn_name_first(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p203_psn_name_first)
                xmla1_psn_name_middle(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p204_psn_name_middle)
                xmla1_psn_name_last(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p205_psn_name_last)
                'id------------------------ 
                xmla1_psn_id_no(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p206_psn_id_no)
                xmla1_psn_id_type(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p207_psn_id_type)
                'location----------------- 
                xmla1_psn_location_addr(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p208_psn_location_addr)
                xmla1_psn_location_phone(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p209_psn_location_phone)
                xmla1_psn_location_fax(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p210_psn_location_fax)
                'office----------------- 
                xmla1_psn_office_occ(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p211_psn_office_occ)
                xmla1_psn_office_org(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p212_psn_office_org)
                xmla1_psn_office_phone(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p213_psn_office_phone)
                xmla1_psn_office_fax(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p214_psn_office_fax)
                xmla1_psn_office_type(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p215_psn_office_type)
                xmla1_psn_office_desc(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p216_psn_office_desc)
                'contact---------------- 
                xmla1_psn_contact_addr(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p217_psn_contact_addr)
                xmla1_psn_contact_phone(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p218_psn_contact_phone)
                xmla1_psn_contact_fax(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p219_psn_contact_fax)
                'iddoc---------------- 
                xmla1_psn_iddoc_type(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p220_psn_iddoc_type)
                xmla1_psn_iddoc_desc(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p221_psn_iddoc_desc)
                xmla1_psn_iddoc_no(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p222_psn_iddoc_no)
                xmla1_psn_iddoc_by(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p223_psn_iddoc_by)
                xmla1_psn_iddoc_date(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p224_psn_iddoc_date)
                xmla1_psn_iddoc_expire(i) = xmldoc.CreateTextNode(pAmlo2Psn(i).p225_psn_iddoc_expire)
                'psn==========End==================
            Next i
            'tsc==========Begin================== 
            xmla1_tsc_date = xmldoc.CreateTextNode(pAmlo2Data.p301_tsc_date)
            xmla1_tsc_type = xmldoc.CreateTextNode(pAmlo2Data.p302_tsc_type)
            xmla1_tsc_desc = xmldoc.CreateTextNode(pAmlo2Data.p303_tsc_desc)

            'asset----------------  
            xmla1_tsc_asset_type = xmldoc.CreateTextNode(pAmlo2Data.p304_tsc_asset_type)
            xmla1_tsc_asset_desc = xmldoc.CreateTextNode(pAmlo2Data.p305_tsc_asset_desc)
            xmla1_tsc_asset_detail = xmldoc.CreateTextNode(pAmlo2Data.p306_tsc_asset_detail)
            xmla1_tsc_asset_amt = xmldoc.CreateTextNode(pAmlo2Data.p307_tsc_asset_amt)
            'acc-------------------    
            xmla1_tsc_acc_accno = xmldoc.CreateTextNode(pAmlo2Data.p308_tsc_acc_accno)
            xmla1_tsc_acc_aname = xmldoc.CreateTextNode(pAmlo2Data.p309_tsc_acc_aname)
            'acc_name-------------------  
            xmla1_tsc_acc_name_prefix = xmldoc.CreateTextNode(pAmlo2Data.p310_tsc_acc_name_prefix)
            xmla1_tsc_acc_name_first = xmldoc.CreateTextNode(pAmlo2Data.p311_tsc_acc_name_first)
            xmla1_tsc_acc_name_middle = xmldoc.CreateTextNode(pAmlo2Data.p312_tsc_acc_name_middle)
            xmla1_tsc_acc_name_last = xmldoc.CreateTextNode(pAmlo2Data.p313_tsc_acc_name_last)
            'racc----------------  
            xmla1_tsc_racc_accno = xmldoc.CreateTextNode(pAmlo2Data.p314_tsc_racc_accno)
            xmla1_tsc_racc_aname = xmldoc.CreateTextNode(pAmlo2Data.p315_tsc_racc_aname)
            'racc_name-------------------   
            xmla1_tsc_racc_name_prefix = xmldoc.CreateTextNode(pAmlo2Data.p316_tsc_racc_name_prefix)
            xmla1_tsc_racc_name_first = xmldoc.CreateTextNode(pAmlo2Data.p317_tsc_racc_name_first)
            xmla1_tsc_racc_name_middle = xmldoc.CreateTextNode(pAmlo2Data.p318_tsc_racc_name_middle)
            xmla1_tsc_racc_name_last = xmldoc.CreateTextNode(pAmlo2Data.p319_tsc_racc_name_last)
            'racc---------------- 
            xmla1_tsc_racc_relation_type = xmldoc.CreateTextNode(pAmlo2Data.p320_tsc_racc_relation_type)
            xmla1_tsc_racc_relation_desc = xmldoc.CreateTextNode(pAmlo2Data.p321_tsc_racc_relation_desc)
            'name-------------------  
            xmla1_tsc_name_prefix = xmldoc.CreateTextNode(pAmlo2Data.p322_tsc_name_prefix)
            xmla1_tsc_name_first = xmldoc.CreateTextNode(pAmlo2Data.p323_tsc_name_first)
            xmla1_tsc_name_middle = xmldoc.CreateTextNode(pAmlo2Data.p324_tsc_name_middle)
            xmla1_tsc_name_last = xmldoc.CreateTextNode(pAmlo2Data.p325_tsc_name_last)

            'obj---------------- 
            xmla1_tsc_obj_type = xmldoc.CreateTextNode(pAmlo2Data.p326_tsc_obj_type)
            xmla1_tsc_obj_desc = xmldoc.CreateTextNode(pAmlo2Data.p327_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            xmla1_record_writer = xmldoc.CreateTextNode(pAmlo2Data.p401_record_writer)
            xmla1_record_sign = xmldoc.CreateTextNode(pAmlo2Data.p402_record_sign)
            xmla1_record_date = xmldoc.CreateTextNode(pAmlo2Data.p403_record_date)
            'record==========End==================

            '// append the nodes to the parentNode without the value
            parentNode.AppendChild(a1_type)
            parentNode.AppendChild(a1_reportid)
            parentNode.AppendChild(a1_revision)
            parentNode.AppendChild(a1_date)
            'cnd==========Begin==================
            parentNode.AppendChild(a1_cnd)
            'name-------------------
            a1_cnd.AppendChild(a1_cnd_name)
            a1_cnd_name.AppendChild(a1_cnd_name_prefix)
            a1_cnd_name.AppendChild(a1_cnd_name_first)
            a1_cnd_name.AppendChild(a1_cnd_name_middle)
            a1_cnd_name.AppendChild(a1_cnd_name_last)
            'id------------------------
            a1_cnd.AppendChild(a1_cnd_id)
            a1_cnd_id.AppendChild(a1_cnd_id_no)
            a1_cnd_id.AppendChild(a1_cnd_id_type)
            'location-----------------
            a1_cnd.AppendChild(a1_cnd_location)
            a1_cnd_location.AppendChild(a1_cnd_location_addr)
            a1_cnd_location.AppendChild(a1_cnd_location_phone)
            a1_cnd_location.AppendChild(a1_cnd_location_fax)
            'office-----------------
            a1_cnd.AppendChild(a1_cnd_office)
            a1_cnd_office.AppendChild(a1_cnd_office_occ)
            a1_cnd_office.AppendChild(a1_cnd_office_desc)
            a1_cnd_office.AppendChild(a1_cnd_office_org)
            a1_cnd_office.AppendChild(a1_cnd_office_phone)
            a1_cnd_office.AppendChild(a1_cnd_office_fax)
            'contact----------------
            a1_cnd.AppendChild(a1_cnd_contact)
            a1_cnd_contact.AppendChild(a1_cnd_contact_addr)
            a1_cnd_contact.AppendChild(a1_cnd_contact_phone)
            a1_cnd_contact.AppendChild(a1_cnd_contact_fax)
            'iddoc----------------
            a1_cnd.AppendChild(a1_cnd_iddoc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_type)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_desc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_no)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_by)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_date)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin==================
                parentNode.AppendChild(a1_psn(i))
                a1_psn(i).AppendChild(a1_psn_relation(i))
                'name-------------------
                a1_psn(i).AppendChild(a1_psn_name(i))
                a1_psn_name(i).AppendChild(a1_psn_name_prefix(i))
                a1_psn_name(i).AppendChild(a1_psn_name_first(i))
                a1_psn_name(i).AppendChild(a1_psn_name_middle(i))
                a1_psn_name(i).AppendChild(a1_psn_name_last(i))
                'id------------------------
                a1_psn(i).AppendChild(a1_psn_id(i))
                a1_psn_id(i).AppendChild(a1_psn_id_no(i))
                a1_psn_id(i).AppendChild(a1_psn_id_type(i))
                'location-----------------
                a1_psn(i).AppendChild(a1_psn_location(i))
                a1_psn_location(i).AppendChild(a1_psn_location_addr(i))
                a1_psn_location(i).AppendChild(a1_psn_location_phone(i))
                a1_psn_location(i).AppendChild(a1_psn_location_fax(i))
                'office-----------------
                a1_psn(i).AppendChild(a1_psn_office(i))
                a1_psn_office(i).AppendChild(a1_psn_office_occ(i))
                a1_psn_office(i).AppendChild(a1_psn_office_org(i))
                a1_psn_office(i).AppendChild(a1_psn_office_phone(i))
                a1_psn_office(i).AppendChild(a1_psn_office_fax(i))
                a1_psn_office(i).AppendChild(a1_psn_office_type(i))
                a1_psn_office(i).AppendChild(a1_psn_office_desc(i))
                'contact----------------
                a1_psn(i).AppendChild(a1_psn_contact(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_addr(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_phone(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_fax(i))
                'iddoc----------------
                a1_psn(i).AppendChild(a1_psn_iddoc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_type(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_desc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_no(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_by(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_date(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_expire(i))
                'psn==========End==================
            Next

            'tsc==========Begin==================
            parentNode.AppendChild(a1_tsc)
            a1_tsc.AppendChild(a1_tsc_date)
            a1_tsc.AppendChild(a1_tsc_type)
            a1_tsc.AppendChild(a1_tsc_desc)

            'asset---------------- 
            a1_tsc.AppendChild(a1_tsc_asset)
            a1_tsc_asset.AppendChild(a1_tsc_asset_type)
            a1_tsc_asset.AppendChild(a1_tsc_asset_desc)
            a1_tsc_asset.AppendChild(a1_tsc_asset_detail)
            a1_tsc_asset.AppendChild(a1_tsc_asset_amt)
            'acc-------------------   
            a1_tsc.AppendChild(a1_tsc_acc)
            a1_tsc_acc.AppendChild(a1_tsc_acc_accno)
            a1_tsc_acc.AppendChild(a1_tsc_acc_aname)

            'acc_name-------------------
            a1_tsc_acc.AppendChild(a1_tsc_acc_name)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_prefix)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_first)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_middle)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_last)

            'racc-------------------   
            a1_tsc.AppendChild(a1_tsc_racc)
            a1_tsc_racc.AppendChild(a1_tsc_racc_accno)
            a1_tsc_racc.AppendChild(a1_tsc_racc_aname)

            'racc_name-------------------
            a1_tsc_racc.AppendChild(a1_tsc_racc_name)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_prefix)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_first)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_middle)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_last)
            'racc_relation---------------- 
            a1_tsc_racc.AppendChild(a1_tsc_racc_relation)
            a1_tsc_racc_relation.AppendChild(a1_tsc_racc_relation_type)
            a1_tsc_racc_relation.AppendChild(a1_tsc_racc_relation_desc)


            'name-------------------
            a1_tsc.AppendChild(a1_tsc_name)
            a1_tsc_name.AppendChild(a1_tsc_name_prefix)
            a1_tsc_name.AppendChild(a1_tsc_name_first)
            a1_tsc_name.AppendChild(a1_tsc_name_middle)
            a1_tsc_name.AppendChild(a1_tsc_name_last)
            'obj----------------
            a1_tsc.AppendChild(a1_tsc_obj)
            a1_tsc_obj.AppendChild(a1_tsc_obj_type)
            a1_tsc_obj.AppendChild(a1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin==================
            parentNode.AppendChild(a1_record)
            a1_record.AppendChild(a1_record_writer)
            a1_record.AppendChild(a1_record_sign)
            a1_record.AppendChild(a1_record_date)
            'record==========End==================

            '// save the value of the fields into the nodes 
            a1_type.AppendChild(xmla1_type)
            a1_reportid.AppendChild(xmla1_reportid)
            a1_revision.AppendChild(xmla1_revision)
            a1_date.AppendChild(xmla1_date)
            'cnd==========Begin================== 
            'name-------------------
            'a1_cnd_name.AppendChild(xmla1_cnd_name)
            a1_cnd_name_prefix.AppendChild(xmla1_cnd_name_prefix)
            a1_cnd_name_first.AppendChild(xmla1_cnd_name_first)
            a1_cnd_name_middle.AppendChild(xmla1_cnd_name_middle)
            a1_cnd_name_last.AppendChild(xmla1_cnd_name_last)
            'id------------------------  
            a1_cnd_id_no.AppendChild(xmla1_cnd_id_no)
            a1_cnd_id_type.AppendChild(xmla1_cnd_id_type)
            'location----------------- 
            a1_cnd_location_addr.AppendChild(xmla1_cnd_location_addr)
            a1_cnd_location_phone.AppendChild(xmla1_cnd_location_phone)
            a1_cnd_location_fax.AppendChild(xmla1_cnd_location_fax)
            'office----------------- 
            a1_cnd_office_occ.AppendChild(xmla1_cnd_office_occ)
            a1_cnd_office_desc.AppendChild(xmla1_cnd_office_desc)
            a1_cnd_office_org.AppendChild(xmla1_cnd_office_org)
            a1_cnd_office_phone.AppendChild(xmla1_cnd_office_phone)
            a1_cnd_office_fax.AppendChild(xmla1_cnd_office_fax)
            'contact---------------- 
            a1_cnd_contact_addr.AppendChild(xmla1_cnd_contact_addr)
            a1_cnd_contact_phone.AppendChild(xmla1_cnd_contact_phone)
            a1_cnd_contact_fax.AppendChild(xmla1_cnd_contact_fax)
            'iddoc---------------- 
            a1_cnd_iddoc_type.AppendChild(xmla1_cnd_iddoc_type)
            a1_cnd_iddoc_desc.AppendChild(xmla1_cnd_iddoc_desc)
            a1_cnd_iddoc_no.AppendChild(xmla1_cnd_iddoc_no)
            a1_cnd_iddoc_by.AppendChild(xmla1_cnd_iddoc_by)
            a1_cnd_iddoc_date.AppendChild(xmla1_cnd_iddoc_date)
            a1_cnd_iddoc_expire.AppendChild(xmla1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                a1_psn_relation(i).AppendChild(xmla1_psn_relation(i))
                'name------------------- 
                a1_psn_name_prefix(i).AppendChild(xmla1_psn_name_prefix(i))
                a1_psn_name_first(i).AppendChild(xmla1_psn_name_first(i))
                a1_psn_name_middle(i).AppendChild(xmla1_psn_name_middle(i))
                a1_psn_name_last(i).AppendChild(xmla1_psn_name_last(i))
                'id------------------------ 
                a1_psn_id_no(i).AppendChild(xmla1_psn_id_no(i))
                a1_psn_id_type(i).AppendChild(xmla1_psn_id_type(i))
                'location----------------- 
                a1_psn_location_addr(i).AppendChild(xmla1_psn_location_addr(i))
                a1_psn_location_phone(i).AppendChild(xmla1_psn_location_phone(i))
                a1_psn_location_fax(i).AppendChild(xmla1_psn_location_fax(i))
                'office----------------- 
                a1_psn_office_occ(i).AppendChild(xmla1_psn_office_occ(i))
                a1_psn_office_org(i).AppendChild(xmla1_psn_office_org(i))
                a1_psn_office_phone(i).AppendChild(xmla1_psn_office_phone(i))
                a1_psn_office_fax(i).AppendChild(xmla1_psn_office_fax(i))
                a1_psn_office_type(i).AppendChild(xmla1_psn_office_type(i))
                a1_psn_office_desc(i).AppendChild(xmla1_psn_office_desc(i))
                'contact---------------- 
                a1_psn_contact_addr(i).AppendChild(xmla1_psn_contact_addr(i))
                a1_psn_contact_phone(i).AppendChild(xmla1_psn_contact_phone(i))
                a1_psn_contact_fax(i).AppendChild(xmla1_psn_contact_fax(i))
                'iddoc---------------- 
                a1_psn_iddoc_type(i).AppendChild(xmla1_psn_iddoc_type(i))
                a1_psn_iddoc_desc(i).AppendChild(xmla1_psn_iddoc_desc(i))
                a1_psn_iddoc_no(i).AppendChild(xmla1_psn_iddoc_no(i))
                a1_psn_iddoc_by(i).AppendChild(xmla1_psn_iddoc_by(i))
                a1_psn_iddoc_date(i).AppendChild(xmla1_psn_iddoc_date(i))
                a1_psn_iddoc_expire(i).AppendChild(xmla1_psn_iddoc_expire(i))
                'psn==========End==================

            Next
            'psn==========Begin================== 

            'tsc==========Begin================== 
            a1_tsc_date.AppendChild(xmla1_tsc_date)
            a1_tsc_type.AppendChild(xmla1_tsc_type)
            a1_tsc_desc.AppendChild(xmla1_tsc_desc)
            'asset---------------- 
            a1_tsc_asset_type.AppendChild(xmla1_tsc_asset_type)
            a1_tsc_asset_desc.AppendChild(xmla1_tsc_asset_desc)
            a1_tsc_asset_detail.AppendChild(xmla1_tsc_asset_detail)
            a1_tsc_asset_amt.AppendChild(xmla1_tsc_asset_amt)
            'acc-------------------   
            a1_tsc_acc_accno.AppendChild(xmla1_tsc_acc_accno)
            a1_tsc_acc_aname.AppendChild(xmla1_tsc_acc_aname)
            'acc_name------------------- 
            a1_tsc_acc_name_prefix.AppendChild(xmla1_tsc_acc_name_prefix)
            a1_tsc_acc_name_first.AppendChild(xmla1_tsc_acc_name_first)
            a1_tsc_acc_name_middle.AppendChild(xmla1_tsc_acc_name_middle)
            a1_tsc_acc_name_last.AppendChild(xmla1_tsc_acc_name_last)
            'racc---------------- 
            a1_tsc_racc_accno.AppendChild(xmla1_tsc_racc_accno)
            a1_tsc_racc_aname.AppendChild(xmla1_tsc_racc_aname)
            'racc_name------------------- 
            a1_tsc_racc_name_prefix.AppendChild(xmla1_tsc_racc_name_prefix)
            a1_tsc_racc_name_first.AppendChild(xmla1_tsc_racc_name_first)
            a1_tsc_racc_name_middle.AppendChild(xmla1_tsc_racc_name_middle)
            a1_tsc_racc_name_last.AppendChild(xmla1_tsc_racc_name_last)
            'racc_relation---------------- 
            a1_tsc_racc_relation_type.AppendChild(xmla1_tsc_racc_relation_type)
            a1_tsc_racc_relation_desc.AppendChild(xmla1_tsc_racc_relation_desc)
            'name------------------- 
            a1_tsc_name_prefix.AppendChild(xmla1_tsc_name_prefix)
            a1_tsc_name_first.AppendChild(xmla1_tsc_name_prefix)
            a1_tsc_name_middle.AppendChild(xmla1_tsc_name_middle)
            a1_tsc_name_last.AppendChild(xmla1_tsc_name_last)
            'obj---------------- 
            a1_tsc_obj_type.AppendChild(xmla1_tsc_obj_type)
            a1_tsc_obj_desc.AppendChild(xmla1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            a1_record_writer.AppendChild(xmla1_record_writer)
            a1_record_sign.AppendChild(xmla1_record_sign)
            a1_record_date.AppendChild(xmla1_record_date)
            'record==========End==================

            '// Save to the XML file
            'xmldoc.Save(filePath)
            Dim ansiWriter As StreamWriter
            ansiWriter = New StreamWriter(filePath, False, Encoding.Default)
            xmldoc.Save(ansiWriter)

            ansiWriter.Close()


            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function AddAMLO3node(ByVal filePath As String, ByVal pAmlo3Data As clsAmlo3Data, ByVal pCountPsn As Integer, ByVal pAmlo3Psn() As clsAmlo3Psn, ByVal intLoop As Integer, ByVal intMaxLoop As Integer) As Boolean
        Try
            Dim i As Integer
            Dim xmldoc As XmlDocument
            xmldoc = New XmlDocument()
            xmldoc.Load(filePath)
            Dim parentNode As XmlElement
            parentNode = xmldoc.CreateElement("doc")
            Dim a0_version As XmlElement
            Dim a0_org As XmlElement
            Dim xmla0_version As XmlText
            Dim xmla0_org As XmlText
            clsDateFormat = New clsDateFormat

            If Not (IsDBNull(xmldoc.DocumentElement)) Then
                xmldoc.DocumentElement.PrependChild(parentNode)
                If (intLoop = intMaxLoop) Then
                    a0_org = xmldoc.CreateElement("org")
                    a0_version = xmldoc.CreateElement("version")

                    xmla0_org = xmldoc.CreateTextNode("ธนาคารอาคารสงเคราะห์")
                    xmla0_version = xmldoc.CreateTextNode("1.1")

                    xmldoc.DocumentElement.PrependChild(a0_org)
                    xmldoc.DocumentElement.PrependChild(a0_version)

                    a0_org.AppendChild(xmla0_org)
                    a0_version.AppendChild(xmla0_version)

                End If

            End If

            ' Create the required nodes 

            Dim a1_type As XmlElement
            Dim a1_reportid As XmlElement
            Dim a1_revision As XmlElement
            Dim a1_date As XmlElement
            Dim a1_refer As XmlElement
            'cnd==========Begin==================
            Dim a1_cnd As XmlElement
            'name-------------------
            Dim a1_cnd_name As XmlElement
            Dim a1_cnd_name_prefix As XmlElement
            Dim a1_cnd_name_first As XmlElement
            Dim a1_cnd_name_middle As XmlElement
            Dim a1_cnd_name_last As XmlElement
            'id------------------------
            Dim a1_cnd_id As XmlElement
            Dim a1_cnd_id_no As XmlElement
            Dim a1_cnd_id_type As XmlElement
            'location-----------------
            Dim a1_cnd_location As XmlElement
            Dim a1_cnd_location_addr As XmlElement
            Dim a1_cnd_location_phone As XmlElement
            Dim a1_cnd_location_fax As XmlElement
            'office-----------------
            Dim a1_cnd_office As XmlElement
            Dim a1_cnd_office_occ As XmlElement
            Dim a1_cnd_office_desc As XmlElement
            Dim a1_cnd_office_org As XmlElement
            Dim a1_cnd_office_phone As XmlElement
            Dim a1_cnd_office_fax As XmlElement
            'contact----------------
            Dim a1_cnd_contact As XmlElement
            Dim a1_cnd_contact_addr As XmlElement
            Dim a1_cnd_contact_phone As XmlElement
            Dim a1_cnd_contact_fax As XmlElement
            'iddoc----------------
            Dim a1_cnd_iddoc As XmlElement
            Dim a1_cnd_iddoc_type As XmlElement
            Dim a1_cnd_iddoc_desc As XmlElement
            Dim a1_cnd_iddoc_no As XmlElement
            Dim a1_cnd_iddoc_by As XmlElement
            Dim a1_cnd_iddoc_date As XmlElement
            Dim a1_cnd_iddoc_expire As XmlElement
            'cnd==========End==================
            'psn==========Begin==================
            Dim a1_psn(pCountPsn) As XmlElement
            Dim a1_psn_relation(pCountPsn) As XmlElement
            'name-------------------
            Dim a1_psn_name(pCountPsn) As XmlElement
            Dim a1_psn_name_prefix(pCountPsn) As XmlElement
            Dim a1_psn_name_first(pCountPsn) As XmlElement
            Dim a1_psn_name_middle(pCountPsn) As XmlElement
            Dim a1_psn_name_last(pCountPsn) As XmlElement
            'id------------------------
            Dim a1_psn_id(pCountPsn) As XmlElement
            Dim a1_psn_id_no(pCountPsn) As XmlElement
            Dim a1_psn_id_type(pCountPsn) As XmlElement
            'location-----------------
            Dim a1_psn_location(pCountPsn) As XmlElement
            Dim a1_psn_location_addr(pCountPsn) As XmlElement
            Dim a1_psn_location_phone(pCountPsn) As XmlElement
            Dim a1_psn_location_fax(pCountPsn) As XmlElement
            'office-----------------
            Dim a1_psn_office(pCountPsn) As XmlElement
            Dim a1_psn_office_occ(pCountPsn) As XmlElement
            Dim a1_psn_office_org(pCountPsn) As XmlElement
            Dim a1_psn_office_phone(pCountPsn) As XmlElement
            Dim a1_psn_office_fax(pCountPsn) As XmlElement
            Dim a1_psn_office_type(pCountPsn) As XmlElement
            Dim a1_psn_office_desc(pCountPsn) As XmlElement
            'contact----------------
            Dim a1_psn_contact(pCountPsn) As XmlElement
            Dim a1_psn_contact_addr(pCountPsn) As XmlElement
            Dim a1_psn_contact_phone(pCountPsn) As XmlElement
            Dim a1_psn_contact_fax(pCountPsn) As XmlElement
            'iddoc----------------
            Dim a1_psn_iddoc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_type(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_desc(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_no(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_by(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_date(pCountPsn) As XmlElement
            Dim a1_psn_iddoc_expire(pCountPsn) As XmlElement
            'psn==========End==================

            'tsc==========Begin==================
            Dim a1_tsc As XmlElement
            Dim a1_tsc_date As XmlElement
            Dim a1_tsc_type As XmlElement
            Dim a1_tsc_desc As XmlElement
            'Dim a1_tsc_cur As XmlElement
            Dim a1_tsc_amt As XmlElement


            'acc-------------------   
            Dim a1_tsc_acc As XmlElement
            Dim a1_tsc_acc_accno As XmlElement
            Dim a1_tsc_acc_aname As XmlElement
            'acc_name------------------- 
            Dim a1_tsc_acc_name As XmlElement
            Dim a1_tsc_acc_name_prefix As XmlElement
            Dim a1_tsc_acc_name_first As XmlElement
            Dim a1_tsc_acc_name_middle As XmlElement
            Dim a1_tsc_acc_name_last As XmlElement
            'racc---------------- 
            Dim a1_tsc_racc As XmlElement
            Dim a1_tsc_racc_accno As XmlElement
            Dim a1_tsc_racc_aname As XmlElement
            'racc_name------------------- 
            Dim a1_tsc_racc_name As XmlElement
            Dim a1_tsc_racc_name_prefix As XmlElement
            Dim a1_tsc_racc_name_first As XmlElement
            Dim a1_tsc_racc_name_middle As XmlElement
            Dim a1_tsc_racc_name_last As XmlElement
            'racc_relation---------------- 
            Dim a1_tsc_racc_relation As XmlElement
            Dim a1_tsc_racc_relation_type As XmlElement
            Dim a1_tsc_racc_relation_desc As XmlElement
            'name------------------- 
            Dim a1_tsc_name As XmlElement
            Dim a1_tsc_name_prefix As XmlElement
            Dim a1_tsc_name_first As XmlElement
            Dim a1_tsc_name_middle As XmlElement
            Dim a1_tsc_name_last As XmlElement
            'obj------------------- 
            Dim a1_tsc_obj As XmlElement
            Dim a1_tsc_obj_type As XmlElement
            Dim a1_tsc_obj_desc As XmlElement

            'tsc==========End==================
            'record==========Begin==================
            'Dim a1_record As XmlElement
            Dim a1_record_note As XmlElement
            'record==========End==================



            a1_type = xmldoc.CreateElement("type")
            a1_reportid = xmldoc.CreateElement("reportid")
            a1_revision = xmldoc.CreateElement("revision")
            a1_date = xmldoc.CreateElement("date")
            a1_refer = xmldoc.CreateElement("refer")

            'cnd==========Begin==================
            a1_cnd = xmldoc.CreateElement("cnd")
            'name-------------------
            a1_cnd_name = xmldoc.CreateElement("name")
            a1_cnd_name_prefix = xmldoc.CreateElement("prefix")
            a1_cnd_name_first = xmldoc.CreateElement("first")
            a1_cnd_name_middle = xmldoc.CreateElement("middle")
            a1_cnd_name_last = xmldoc.CreateElement("last")
            'id------------------------
            a1_cnd_id = xmldoc.CreateElement("id")
            a1_cnd_id_no = xmldoc.CreateElement("no")
            a1_cnd_id_type = xmldoc.CreateElement("type")
            'location-----------------
            a1_cnd_location = xmldoc.CreateElement("location")
            a1_cnd_location_addr = xmldoc.CreateElement("addr")
            a1_cnd_location_phone = xmldoc.CreateElement("phone")
            a1_cnd_location_fax = xmldoc.CreateElement("fax")
            'office-----------------
            a1_cnd_office = xmldoc.CreateElement("office")
            a1_cnd_office_occ = xmldoc.CreateElement("occ")
            a1_cnd_office_desc = xmldoc.CreateElement("desc")
            a1_cnd_office_org = xmldoc.CreateElement("org")
            a1_cnd_office_phone = xmldoc.CreateElement("phone")
            a1_cnd_office_fax = xmldoc.CreateElement("fax")
            'contact----------------
            a1_cnd_contact = xmldoc.CreateElement("contact")
            a1_cnd_contact_addr = xmldoc.CreateElement("addr")
            a1_cnd_contact_phone = xmldoc.CreateElement("phone")
            a1_cnd_contact_fax = xmldoc.CreateElement("fax")
            'iddoc----------------
            a1_cnd_iddoc = xmldoc.CreateElement("iddoc")
            a1_cnd_iddoc_type = xmldoc.CreateElement("type")
            a1_cnd_iddoc_desc = xmldoc.CreateElement("desc")
            a1_cnd_iddoc_no = xmldoc.CreateElement("no")
            a1_cnd_iddoc_by = xmldoc.CreateElement("by")
            a1_cnd_iddoc_date = xmldoc.CreateElement("date")
            a1_cnd_iddoc_expire = xmldoc.CreateElement("expire")
            'cnd==========End==================

            For i = 1 To pCountPsn
                'psn==========Begin==================
                a1_psn(i) = xmldoc.CreateElement("psn")
                a1_psn_relation(i) = xmldoc.CreateElement("relation")
                'name-------------------
                a1_psn_name(i) = xmldoc.CreateElement("name")
                a1_psn_name_prefix(i) = xmldoc.CreateElement("prefix")
                a1_psn_name_first(i) = xmldoc.CreateElement("first")
                a1_psn_name_middle(i) = xmldoc.CreateElement("middle")
                a1_psn_name_last(i) = xmldoc.CreateElement("last")
                'id------------------------
                a1_psn_id(i) = xmldoc.CreateElement("id")
                a1_psn_id_no(i) = xmldoc.CreateElement("no")
                a1_psn_id_type(i) = xmldoc.CreateElement("type")
                'location-----------------
                a1_psn_location(i) = xmldoc.CreateElement("location")
                a1_psn_location_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_location_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_location_fax(i) = xmldoc.CreateElement("fax")
                'office-----------------
                a1_psn_office(i) = xmldoc.CreateElement("office")
                a1_psn_office_occ(i) = xmldoc.CreateElement("occ")
                a1_psn_office_org(i) = xmldoc.CreateElement("org")
                a1_psn_office_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_office_fax(i) = xmldoc.CreateElement("fax")
                a1_psn_office_type(i) = xmldoc.CreateElement("type")
                a1_psn_office_desc(i) = xmldoc.CreateElement("desc")
                'contact----------------
                a1_psn_contact(i) = xmldoc.CreateElement("contact")
                a1_psn_contact_addr(i) = xmldoc.CreateElement("addr")
                a1_psn_contact_phone(i) = xmldoc.CreateElement("phone")
                a1_psn_contact_fax(i) = xmldoc.CreateElement("fax")
                'iddoc----------------
                a1_psn_iddoc(i) = xmldoc.CreateElement("iddoc")
                a1_psn_iddoc_type(i) = xmldoc.CreateElement("type")
                a1_psn_iddoc_desc(i) = xmldoc.CreateElement("desc")
                a1_psn_iddoc_no(i) = xmldoc.CreateElement("no")
                a1_psn_iddoc_by(i) = xmldoc.CreateElement("by")
                a1_psn_iddoc_date(i) = xmldoc.CreateElement("date")
                a1_psn_iddoc_expire(i) = xmldoc.CreateElement("expire")
                'psn==========End==================
            Next


            'tsc==========Begin==================
            a1_tsc = xmldoc.CreateElement("tsc")
            a1_tsc_date = xmldoc.CreateElement("date")
            a1_tsc_type = xmldoc.CreateElement("type")
            a1_tsc_desc = xmldoc.CreateElement("desc")
            'a1_tsc_cur = xmldoc.CreateElement("cur")
            a1_tsc_amt = xmldoc.CreateElement("amt")
            'acc-------------------   
            a1_tsc_acc = xmldoc.CreateElement("acc")
            a1_tsc_acc_accno = xmldoc.CreateElement("accno")
            a1_tsc_acc_aname = xmldoc.CreateElement("aname")
            'acc_name------------------- 
            a1_tsc_acc_name = xmldoc.CreateElement("name")
            a1_tsc_acc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_acc_name_first = xmldoc.CreateElement("first")
            a1_tsc_acc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_acc_name_last = xmldoc.CreateElement("last")
            'racc---------------- 
            a1_tsc_racc = xmldoc.CreateElement("racc")
            a1_tsc_racc_accno = xmldoc.CreateElement("accno")
            a1_tsc_racc_aname = xmldoc.CreateElement("aname")
            'racc_name------------------- 
            a1_tsc_racc_name = xmldoc.CreateElement("name")
            a1_tsc_racc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_racc_name_first = xmldoc.CreateElement("first")
            a1_tsc_racc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_racc_name_last = xmldoc.CreateElement("last")
            'racc---------------- 
            a1_tsc_racc_relation = xmldoc.CreateElement("relation")
            a1_tsc_racc_relation_type = xmldoc.CreateElement("type")
            a1_tsc_racc_relation_desc = xmldoc.CreateElement("desc")
            'name------------------- 
            a1_tsc_name = xmldoc.CreateElement("name")
            a1_tsc_name_prefix = xmldoc.CreateElement("prefix")
            a1_tsc_name_first = xmldoc.CreateElement("first")
            a1_tsc_name_middle = xmldoc.CreateElement("middle")
            a1_tsc_name_last = xmldoc.CreateElement("last")
            'obj------------------- 
            a1_tsc_obj = xmldoc.CreateElement("obj")
            a1_tsc_obj_type = xmldoc.CreateElement("type")
            a1_tsc_obj_desc = xmldoc.CreateElement("desc")


            'tsc==========End==================
            'record==========Begin==================
            'a1_record = xmldoc.CreateElement("record")
            a1_record_note = xmldoc.CreateElement("note")

            'record==========End==================

            Dim xmla1_type As XmlText
            Dim xmla1_reportid As XmlText
            Dim xmla1_revision As XmlText
            Dim xmla1_date As XmlText
            Dim xmla1_refer As XmlText

            'cnd==========Begin==================
            ' Dim xmla1_cnd As XmlText
            'name-------------------
            'Dim xmla1_cnd_name As XmlText
            Dim xmla1_cnd_name_prefix As XmlText
            Dim xmla1_cnd_name_first As XmlText
            Dim xmla1_cnd_name_middle As XmlText
            Dim xmla1_cnd_name_last As XmlText
            'id------------------------
            'Dim xmla1_cnd_id As XmlText
            Dim xmla1_cnd_id_no As XmlText
            Dim xmla1_cnd_id_type As XmlText
            'location-----------------
            'Dim xmla1_cnd_location As XmlText
            Dim xmla1_cnd_location_addr As XmlText
            Dim xmla1_cnd_location_phone As XmlText
            Dim xmla1_cnd_location_fax As XmlText
            'office-----------------
            'Dim xmla1_cnd_office As XmlText
            Dim xmla1_cnd_office_occ As XmlText
            Dim xmla1_cnd_office_desc As XmlText
            Dim xmla1_cnd_office_org As XmlText
            Dim xmla1_cnd_office_phone As XmlText
            Dim xmla1_cnd_office_fax As XmlText
            'contact----------------
            'Dim xmla1_cnd_contact As XmlText
            Dim xmla1_cnd_contact_addr As XmlText
            Dim xmla1_cnd_contact_phone As XmlText
            Dim xmla1_cnd_contact_fax As XmlText
            'iddoc----------------
            'Dim xmla1_cnd_iddoc As XmlText
            Dim xmla1_cnd_iddoc_type As XmlText
            Dim xmla1_cnd_iddoc_desc As XmlText
            Dim xmla1_cnd_iddoc_no As XmlText
            Dim xmla1_cnd_iddoc_by As XmlText
            Dim xmla1_cnd_iddoc_date As XmlText
            Dim xmla1_cnd_iddoc_expire As XmlText
            'cnd==========End==================
            'psn==========Begin==================
            'Dim xmla1_psn As XmlText
            Dim xmla1_psn_relation(pCountPsn) As XmlText
            'name-------------------
            'Dim xmla1_psn_name As XmlText
            Dim xmla1_psn_name_prefix(pCountPsn) As XmlText
            Dim xmla1_psn_name_first(pCountPsn) As XmlText
            Dim xmla1_psn_name_middle(pCountPsn) As XmlText
            Dim xmla1_psn_name_last(pCountPsn) As XmlText
            'id------------------------
            'Dim xmla1_psn_id As XmlText
            Dim xmla1_psn_id_no(pCountPsn) As XmlText
            Dim xmla1_psn_id_type(pCountPsn) As XmlText
            'location-----------------
            'Dim xmla1_psn_location As XmlText
            Dim xmla1_psn_location_addr(pCountPsn) As XmlText
            Dim xmla1_psn_location_phone(pCountPsn) As XmlText
            Dim xmla1_psn_location_fax(pCountPsn) As XmlText
            'office-----------------
            'Dim xmla1_psn_office As XmlText
            Dim xmla1_psn_office_occ(pCountPsn) As XmlText
            Dim xmla1_psn_office_org(pCountPsn) As XmlText
            Dim xmla1_psn_office_phone(pCountPsn) As XmlText
            Dim xmla1_psn_office_fax(pCountPsn) As XmlText
            Dim xmla1_psn_office_type(pCountPsn) As XmlText
            Dim xmla1_psn_office_desc(pCountPsn) As XmlText
            'contact----------------
            'Dim xmla1_psn_contact As XmlText
            Dim xmla1_psn_contact_addr(pCountPsn) As XmlText
            Dim xmla1_psn_contact_phone(pCountPsn) As XmlText
            Dim xmla1_psn_contact_fax(pCountPsn) As XmlText
            'iddoc----------------
            'Dim xmla1_psn_iddoc As XmlText
            Dim xmla1_psn_iddoc_type(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_desc(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_no(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_by(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_date(pCountPsn) As XmlText
            Dim xmla1_psn_iddoc_expire(pCountPsn) As XmlText
            'psn==========End==================

            'tsc==========Begin==================
            'Dim xmla1_tsc As XmlText
            Dim xmla1_tsc_date As XmlText
            Dim xmla1_tsc_type As XmlText
            Dim xmla1_tsc_desc As XmlText
            'Dim xmla1_tsc_cur As XmlText
            Dim xmla1_tsc_amt As XmlText

            'acc-------------------   

            Dim xmla1_tsc_acc_accno As XmlText
            Dim xmla1_tsc_acc_aname As XmlText
            'acc_name------------------- 

            Dim xmla1_tsc_acc_name_prefix As XmlText
            Dim xmla1_tsc_acc_name_first As XmlText
            Dim xmla1_tsc_acc_name_middle As XmlText
            Dim xmla1_tsc_acc_name_last As XmlText

            'racc---------------- 

            Dim xmla1_tsc_racc_accno As XmlText
            Dim xmla1_tsc_racc_aname As XmlText
            'racc_name------------------- 

            Dim xmla1_tsc_racc_name_prefix As XmlText
            Dim xmla1_tsc_racc_name_first As XmlText
            Dim xmla1_tsc_racc_name_middle As XmlText
            Dim xmla1_tsc_racc_name_last As XmlText
            'racc_relation---------------- 

            Dim xmla1_tsc_racc_relation_type As XmlText
            Dim xmla1_tsc_racc_relation_desc As XmlText
            'name-------------------
            'Dim xmla1_tsc_name As XmlText
            Dim xmla1_tsc_name_prefix As XmlText
            Dim xmla1_tsc_name_first As XmlText
            Dim xmla1_tsc_name_middle As XmlText
            Dim xmla1_tsc_name_last As XmlText
            'obj----------------
            'Dim xmla1_tsc_obj As XmlText
            Dim xmla1_tsc_obj_type As XmlText
            Dim xmla1_tsc_obj_desc As XmlText
            'tsc==========End==================
            'record==========Begin==================
            'Dim xmla1_record As XmlText
            Dim xmla1_record_note As XmlText

            'record==========End==================

            xmla1_type = xmldoc.CreateTextNode(pAmlo3Data.p01_type)
            xmla1_reportid = xmldoc.CreateTextNode(pAmlo3Data.p02_reportid)
            xmla1_revision = xmldoc.CreateTextNode(pAmlo3Data.p03_revision)
            xmla1_date = xmldoc.CreateTextNode(pAmlo3Data.p04_date)
            xmla1_refer = xmldoc.CreateTextNode(pAmlo3Data.p05_refer)

            'cnd==========Begin================== 
            'name------------------- 
            xmla1_cnd_name_prefix = xmldoc.CreateTextNode(pAmlo3Data.p101_cnd_name_prefix)
            xmla1_cnd_name_first = xmldoc.CreateTextNode(pAmlo3Data.p102_cnd_name_first)
            xmla1_cnd_name_middle = xmldoc.CreateTextNode(pAmlo3Data.p103_cnd_name_middle)
            xmla1_cnd_name_last = xmldoc.CreateTextNode(pAmlo3Data.p104_cnd_name_last)
            'id------------------------ 
            xmla1_cnd_id_no = xmldoc.CreateTextNode(pAmlo3Data.p105_cnd_id_no)
            xmla1_cnd_id_type = xmldoc.CreateTextNode(pAmlo3Data.p106_cnd_id_type)
            'location----------------- 
            xmla1_cnd_location_addr = xmldoc.CreateTextNode(pAmlo3Data.p107_cnd_location_addr)
            xmla1_cnd_location_phone = xmldoc.CreateTextNode(pAmlo3Data.p108_cnd_location_phone)
            xmla1_cnd_location_fax = xmldoc.CreateTextNode(pAmlo3Data.p109_cnd_location_fax)
            'office----------------- 
            xmla1_cnd_office_occ = xmldoc.CreateTextNode(pAmlo3Data.p110_cnd_office_occ)
            xmla1_cnd_office_desc = xmldoc.CreateTextNode(pAmlo3Data.p111_cnd_office_desc)
            xmla1_cnd_office_org = xmldoc.CreateTextNode(pAmlo3Data.p112_cnd_office_org)
            xmla1_cnd_office_phone = xmldoc.CreateTextNode(pAmlo3Data.p113_cnd_office_phone)
            xmla1_cnd_office_fax = xmldoc.CreateTextNode(pAmlo3Data.p114_cnd_office_fax)
            'contact---------------- 
            xmla1_cnd_contact_addr = xmldoc.CreateTextNode(pAmlo3Data.p115_cnd_contact_addr)
            xmla1_cnd_contact_phone = xmldoc.CreateTextNode(pAmlo3Data.p116_cnd_contact_phone)
            xmla1_cnd_contact_fax = xmldoc.CreateTextNode(pAmlo3Data.p117_cnd_contact_fax)
            'iddoc---------------- 
            xmla1_cnd_iddoc_type = xmldoc.CreateTextNode(pAmlo3Data.p118_cnd_iddoc_type)
            xmla1_cnd_iddoc_desc = xmldoc.CreateTextNode(pAmlo3Data.p119_cnd_iddoc_desc)
            xmla1_cnd_iddoc_no = xmldoc.CreateTextNode(pAmlo3Data.p120_cnd_iddoc_no)
            xmla1_cnd_iddoc_by = xmldoc.CreateTextNode(pAmlo3Data.p121_cnd_iddoc_by)
            xmla1_cnd_iddoc_date = xmldoc.CreateTextNode(pAmlo3Data.p122_cnd_iddoc_date)
            xmla1_cnd_iddoc_expire = xmldoc.CreateTextNode(pAmlo3Data.p123_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin================== 
                xmla1_psn_relation(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p201_psn_relation)
                'name------------------- 
                xmla1_psn_name_prefix(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p202_psn_name_prefix)
                xmla1_psn_name_first(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p203_psn_name_first)
                xmla1_psn_name_middle(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p204_psn_name_middle)
                xmla1_psn_name_last(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p205_psn_name_last)
                'id------------------------ 
                xmla1_psn_id_no(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p206_psn_id_no)
                xmla1_psn_id_type(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p207_psn_id_type)
                'location----------------- 
                xmla1_psn_location_addr(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p208_psn_location_addr)
                xmla1_psn_location_phone(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p209_psn_location_phone)
                xmla1_psn_location_fax(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p210_psn_location_fax)
                'office----------------- 
                xmla1_psn_office_occ(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p211_psn_office_occ)
                xmla1_psn_office_org(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p212_psn_office_org)
                xmla1_psn_office_phone(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p213_psn_office_phone)
                xmla1_psn_office_fax(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p214_psn_office_fax)
                xmla1_psn_office_type(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p215_psn_office_type)
                xmla1_psn_office_desc(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p216_psn_office_desc)
                'contact---------------- 
                xmla1_psn_contact_addr(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p217_psn_contact_addr)
                xmla1_psn_contact_phone(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p218_psn_contact_phone)
                xmla1_psn_contact_fax(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p219_psn_contact_fax)
                'iddoc---------------- 
                xmla1_psn_iddoc_type(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p220_psn_iddoc_type)
                xmla1_psn_iddoc_desc(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p221_psn_iddoc_desc)
                xmla1_psn_iddoc_no(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p222_psn_iddoc_no)
                xmla1_psn_iddoc_by(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p223_psn_iddoc_by)
                xmla1_psn_iddoc_date(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p224_psn_iddoc_date)
                xmla1_psn_iddoc_expire(i) = xmldoc.CreateTextNode(pAmlo3Psn(i).p225_psn_iddoc_expire)
                'psn==========End==================
            Next i
            'tsc==========Begin================== 
            xmla1_tsc_date = xmldoc.CreateTextNode(pAmlo3Data.p301_tsc_date)
            xmla1_tsc_type = xmldoc.CreateTextNode(pAmlo3Data.p302_tsc_type)
            xmla1_tsc_desc = xmldoc.CreateTextNode(pAmlo3Data.p303_tsc_desc)
            'xmla1_tsc_cur = xmldoc.CreateTextNode(pAmlo3Data.p304_tsc_cur)
            xmla1_tsc_amt = xmldoc.CreateTextNode(pAmlo3Data.p305_tsc_amt)

            'acc-------------------    
            xmla1_tsc_acc_accno = xmldoc.CreateTextNode(pAmlo3Data.p306_tsc_acc_accno)
            xmla1_tsc_acc_aname = xmldoc.CreateTextNode(pAmlo3Data.p307_tsc_acc_aname)
            'acc_name-------------------  
            xmla1_tsc_acc_name_prefix = xmldoc.CreateTextNode(pAmlo3Data.p308_tsc_acc_name_prefix)
            xmla1_tsc_acc_name_first = xmldoc.CreateTextNode(pAmlo3Data.p309_tsc_acc_name_first)
            xmla1_tsc_acc_name_middle = xmldoc.CreateTextNode(pAmlo3Data.p310_tsc_acc_name_middle)
            xmla1_tsc_acc_name_last = xmldoc.CreateTextNode(pAmlo3Data.p311_tsc_acc_name_last)
            'racc----------------  
            xmla1_tsc_racc_accno = xmldoc.CreateTextNode(pAmlo3Data.p312_tsc_racc_accno)
            xmla1_tsc_racc_aname = xmldoc.CreateTextNode(pAmlo3Data.p313_tsc_racc_aname)
            'racc_name-------------------   
            xmla1_tsc_racc_name_prefix = xmldoc.CreateTextNode(pAmlo3Data.p314_tsc_racc_name_prefix)
            xmla1_tsc_racc_name_first = xmldoc.CreateTextNode(pAmlo3Data.p315_tsc_racc_name_first)
            xmla1_tsc_racc_name_middle = xmldoc.CreateTextNode(pAmlo3Data.p316_tsc_racc_name_middle)
            xmla1_tsc_racc_name_last = xmldoc.CreateTextNode(pAmlo3Data.p317_tsc_racc_name_last)
            'racc---------------- 
            xmla1_tsc_racc_relation_type = xmldoc.CreateTextNode(pAmlo3Data.p318_tsc_racc_relation_type)
            xmla1_tsc_racc_relation_desc = xmldoc.CreateTextNode(pAmlo3Data.p319_tsc_racc_relation_desc)
            'name-------------------  
            xmla1_tsc_name_prefix = xmldoc.CreateTextNode(pAmlo3Data.p320_tsc_name_prefix)
            xmla1_tsc_name_first = xmldoc.CreateTextNode(pAmlo3Data.p321_tsc_name_first)
            xmla1_tsc_name_middle = xmldoc.CreateTextNode(pAmlo3Data.p322_tsc_name_middle)
            xmla1_tsc_name_last = xmldoc.CreateTextNode(pAmlo3Data.p323_tsc_name_last)

            'obj---------------- 
            xmla1_tsc_obj_type = xmldoc.CreateTextNode(pAmlo3Data.p324_tsc_obj_type)
            xmla1_tsc_obj_desc = xmldoc.CreateTextNode(pAmlo3Data.p325_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            xmla1_record_note = xmldoc.CreateTextNode(pAmlo3Data.p401_record_note)

            'record==========End==================

            '// append the nodes to the parentNode without the value
            parentNode.AppendChild(a1_type)
            parentNode.AppendChild(a1_reportid)
            parentNode.AppendChild(a1_revision)
            parentNode.AppendChild(a1_date)
            parentNode.AppendChild(a1_refer)

            'cnd==========Begin==================
            parentNode.AppendChild(a1_cnd)
            'name-------------------
            a1_cnd.AppendChild(a1_cnd_name)
            a1_cnd_name.AppendChild(a1_cnd_name_prefix)
            a1_cnd_name.AppendChild(a1_cnd_name_first)
            a1_cnd_name.AppendChild(a1_cnd_name_middle)
            a1_cnd_name.AppendChild(a1_cnd_name_last)
            'id------------------------
            a1_cnd.AppendChild(a1_cnd_id)
            a1_cnd_id.AppendChild(a1_cnd_id_no)
            a1_cnd_id.AppendChild(a1_cnd_id_type)
            'location-----------------
            a1_cnd.AppendChild(a1_cnd_location)
            a1_cnd_location.AppendChild(a1_cnd_location_addr)
            a1_cnd_location.AppendChild(a1_cnd_location_phone)
            a1_cnd_location.AppendChild(a1_cnd_location_fax)
            'office-----------------
            a1_cnd.AppendChild(a1_cnd_office)
            a1_cnd_office.AppendChild(a1_cnd_office_occ)
            a1_cnd_office.AppendChild(a1_cnd_office_desc)
            a1_cnd_office.AppendChild(a1_cnd_office_org)
            a1_cnd_office.AppendChild(a1_cnd_office_phone)
            a1_cnd_office.AppendChild(a1_cnd_office_fax)
            'contact----------------
            a1_cnd.AppendChild(a1_cnd_contact)
            a1_cnd_contact.AppendChild(a1_cnd_contact_addr)
            a1_cnd_contact.AppendChild(a1_cnd_contact_phone)
            a1_cnd_contact.AppendChild(a1_cnd_contact_fax)
            'iddoc----------------
            a1_cnd.AppendChild(a1_cnd_iddoc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_type)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_desc)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_no)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_by)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_date)
            a1_cnd_iddoc.AppendChild(a1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                'psn==========Begin==================
                parentNode.AppendChild(a1_psn(i))
                a1_psn(i).AppendChild(a1_psn_relation(i))
                'name-------------------
                a1_psn(i).AppendChild(a1_psn_name(i))
                a1_psn_name(i).AppendChild(a1_psn_name_prefix(i))
                a1_psn_name(i).AppendChild(a1_psn_name_first(i))
                a1_psn_name(i).AppendChild(a1_psn_name_middle(i))
                a1_psn_name(i).AppendChild(a1_psn_name_last(i))
                'id------------------------
                a1_psn(i).AppendChild(a1_psn_id(i))
                a1_psn_id(i).AppendChild(a1_psn_id_no(i))
                a1_psn_id(i).AppendChild(a1_psn_id_type(i))
                'location-----------------
                a1_psn(i).AppendChild(a1_psn_location(i))
                a1_psn_location(i).AppendChild(a1_psn_location_addr(i))
                a1_psn_location(i).AppendChild(a1_psn_location_phone(i))
                a1_psn_location(i).AppendChild(a1_psn_location_fax(i))
                'office-----------------
                a1_psn(i).AppendChild(a1_psn_office(i))
                a1_psn_office(i).AppendChild(a1_psn_office_occ(i))
                a1_psn_office(i).AppendChild(a1_psn_office_org(i))
                a1_psn_office(i).AppendChild(a1_psn_office_phone(i))
                a1_psn_office(i).AppendChild(a1_psn_office_fax(i))
                a1_psn_office(i).AppendChild(a1_psn_office_type(i))
                a1_psn_office(i).AppendChild(a1_psn_office_desc(i))
                'contact----------------
                a1_psn(i).AppendChild(a1_psn_contact(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_addr(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_phone(i))
                a1_psn_contact(i).AppendChild(a1_psn_contact_fax(i))
                'iddoc----------------
                a1_psn(i).AppendChild(a1_psn_iddoc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_type(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_desc(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_no(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_by(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_date(i))
                a1_psn_iddoc(i).AppendChild(a1_psn_iddoc_expire(i))
                'psn==========End==================

            Next

            'tsc==========Begin==================
            parentNode.AppendChild(a1_tsc)
            a1_tsc.AppendChild(a1_tsc_date)
            a1_tsc.AppendChild(a1_tsc_type)
            a1_tsc.AppendChild(a1_tsc_amt)

            'acc-------------------   
            a1_tsc.AppendChild(a1_tsc_acc)
            a1_tsc_acc.AppendChild(a1_tsc_acc_accno)
            a1_tsc_acc.AppendChild(a1_tsc_acc_aname)

            'acc_name-------------------
            a1_tsc_acc.AppendChild(a1_tsc_acc_name)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_prefix)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_first)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_middle)
            a1_tsc_acc_name.AppendChild(a1_tsc_acc_name_last)

            'racc-------------------   
            a1_tsc.AppendChild(a1_tsc_racc)
            a1_tsc_racc.AppendChild(a1_tsc_racc_accno)
            a1_tsc_racc.AppendChild(a1_tsc_racc_aname)

            'racc_name-------------------
            a1_tsc_racc.AppendChild(a1_tsc_racc_name)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_prefix)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_first)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_middle)
            a1_tsc_racc_name.AppendChild(a1_tsc_racc_name_last)
            'racc_relation---------------- 
            a1_tsc_racc.AppendChild(a1_tsc_racc_relation)
            a1_tsc_racc_relation.AppendChild(a1_tsc_racc_relation_type)
            a1_tsc_racc_relation.AppendChild(a1_tsc_racc_relation_desc)


            'name-------------------
            a1_tsc.AppendChild(a1_tsc_name)
            a1_tsc_name.AppendChild(a1_tsc_name_prefix)
            a1_tsc_name.AppendChild(a1_tsc_name_first)
            a1_tsc_name.AppendChild(a1_tsc_name_middle)
            a1_tsc_name.AppendChild(a1_tsc_name_last)
            'obj----------------
            a1_tsc.AppendChild(a1_tsc_obj)
            a1_tsc_obj.AppendChild(a1_tsc_obj_type)
            a1_tsc_obj.AppendChild(a1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin==================
            'parentNode.AppendChild(a1_record)
            parentNode.AppendChild(a1_record_note)

            'record==========End==================

            '// save the value of the fields into the nodes 
            a1_type.AppendChild(xmla1_type)
            a1_reportid.AppendChild(xmla1_reportid)
            a1_revision.AppendChild(xmla1_revision)
            a1_date.AppendChild(xmla1_date)
            a1_refer.AppendChild(xmla1_refer)
            'cnd==========Begin================== 
            'name-------------------
            'a1_cnd_name.AppendChild(xmla1_cnd_name)
            a1_cnd_name_prefix.AppendChild(xmla1_cnd_name_prefix)
            a1_cnd_name_first.AppendChild(xmla1_cnd_name_first)
            a1_cnd_name_middle.AppendChild(xmla1_cnd_name_middle)
            a1_cnd_name_last.AppendChild(xmla1_cnd_name_last)
            'id------------------------  
            a1_cnd_id_no.AppendChild(xmla1_cnd_id_no)
            a1_cnd_id_type.AppendChild(xmla1_cnd_id_type)
            'location----------------- 
            a1_cnd_location_addr.AppendChild(xmla1_cnd_location_addr)
            a1_cnd_location_phone.AppendChild(xmla1_cnd_location_phone)
            a1_cnd_location_fax.AppendChild(xmla1_cnd_location_fax)
            'office----------------- 
            a1_cnd_office_occ.AppendChild(xmla1_cnd_office_occ)
            a1_cnd_office_desc.AppendChild(xmla1_cnd_office_desc)
            a1_cnd_office_org.AppendChild(xmla1_cnd_office_org)
            a1_cnd_office_phone.AppendChild(xmla1_cnd_office_phone)
            a1_cnd_office_fax.AppendChild(xmla1_cnd_office_fax)
            'contact---------------- 
            a1_cnd_contact_addr.AppendChild(xmla1_cnd_contact_addr)
            a1_cnd_contact_phone.AppendChild(xmla1_cnd_contact_phone)
            a1_cnd_contact_fax.AppendChild(xmla1_cnd_contact_fax)
            'iddoc---------------- 
            a1_cnd_iddoc_type.AppendChild(xmla1_cnd_iddoc_type)
            a1_cnd_iddoc_desc.AppendChild(xmla1_cnd_iddoc_desc)
            a1_cnd_iddoc_no.AppendChild(xmla1_cnd_iddoc_no)
            a1_cnd_iddoc_by.AppendChild(xmla1_cnd_iddoc_by)
            a1_cnd_iddoc_date.AppendChild(xmla1_cnd_iddoc_date)
            a1_cnd_iddoc_expire.AppendChild(xmla1_cnd_iddoc_expire)
            'cnd==========End==================
            For i = 1 To pCountPsn
                a1_psn_relation(i).AppendChild(xmla1_psn_relation(i))
                'name------------------- 
                a1_psn_name_prefix(i).AppendChild(xmla1_psn_name_prefix(i))
                a1_psn_name_first(i).AppendChild(xmla1_psn_name_first(i))
                a1_psn_name_middle(i).AppendChild(xmla1_psn_name_middle(i))
                a1_psn_name_last(i).AppendChild(xmla1_psn_name_last(i))
                'id------------------------ 
                a1_psn_id_no(i).AppendChild(xmla1_psn_id_no(i))
                a1_psn_id_type(i).AppendChild(xmla1_psn_id_type(i))
                'location----------------- 
                a1_psn_location_addr(i).AppendChild(xmla1_psn_location_addr(i))
                a1_psn_location_phone(i).AppendChild(xmla1_psn_location_phone(i))
                a1_psn_location_fax(i).AppendChild(xmla1_psn_location_fax(i))
                'office----------------- 
                a1_psn_office_occ(i).AppendChild(xmla1_psn_office_occ(i))
                a1_psn_office_org(i).AppendChild(xmla1_psn_office_org(i))
                a1_psn_office_phone(i).AppendChild(xmla1_psn_office_phone(i))
                a1_psn_office_fax(i).AppendChild(xmla1_psn_office_fax(i))
                a1_psn_office_type(i).AppendChild(xmla1_psn_office_type(i))
                a1_psn_office_desc(i).AppendChild(xmla1_psn_office_desc(i))
                'contact---------------- 
                a1_psn_contact_addr(i).AppendChild(xmla1_psn_contact_addr(i))
                a1_psn_contact_phone(i).AppendChild(xmla1_psn_contact_phone(i))
                a1_psn_contact_fax(i).AppendChild(xmla1_psn_contact_fax(i))
                'iddoc---------------- 
                a1_psn_iddoc_type(i).AppendChild(xmla1_psn_iddoc_type(i))
                a1_psn_iddoc_desc(i).AppendChild(xmla1_psn_iddoc_desc(i))
                a1_psn_iddoc_no(i).AppendChild(xmla1_psn_iddoc_no(i))
                a1_psn_iddoc_by(i).AppendChild(xmla1_psn_iddoc_by(i))
                a1_psn_iddoc_date(i).AppendChild(xmla1_psn_iddoc_date(i))
                a1_psn_iddoc_expire(i).AppendChild(xmla1_psn_iddoc_expire(i))
                'psn==========End==================

            Next
            'psn==========Begin================== 

            'tsc==========Begin================== 
            a1_tsc_date.AppendChild(xmla1_tsc_date)
            a1_tsc_type.AppendChild(xmla1_tsc_type)
            a1_tsc_amt.AppendChild(xmla1_tsc_amt)

            'acc-------------------   
            a1_tsc_acc_accno.AppendChild(xmla1_tsc_acc_accno)
            a1_tsc_acc_aname.AppendChild(xmla1_tsc_acc_aname)
            'acc_name------------------- 
            a1_tsc_acc_name_prefix.AppendChild(xmla1_tsc_acc_name_prefix)
            a1_tsc_acc_name_first.AppendChild(xmla1_tsc_acc_name_first)
            a1_tsc_acc_name_middle.AppendChild(xmla1_tsc_acc_name_middle)
            a1_tsc_acc_name_last.AppendChild(xmla1_tsc_acc_name_last)
            'racc---------------- 
            a1_tsc_racc_accno.AppendChild(xmla1_tsc_racc_accno)
            a1_tsc_racc_aname.AppendChild(xmla1_tsc_racc_aname)
            'racc_name------------------- 
            a1_tsc_racc_name_prefix.AppendChild(xmla1_tsc_racc_name_prefix)
            a1_tsc_racc_name_first.AppendChild(xmla1_tsc_racc_name_first)
            a1_tsc_racc_name_middle.AppendChild(xmla1_tsc_racc_name_middle)
            a1_tsc_racc_name_last.AppendChild(xmla1_tsc_racc_name_last)
            'racc_relation---------------- 
            a1_tsc_racc_relation_type.AppendChild(xmla1_tsc_racc_relation_type)
            a1_tsc_racc_relation_desc.AppendChild(xmla1_tsc_racc_relation_desc)
            'name------------------- 
            a1_tsc_name_prefix.AppendChild(xmla1_tsc_name_prefix)
            a1_tsc_name_first.AppendChild(xmla1_tsc_name_first)
            a1_tsc_name_middle.AppendChild(xmla1_tsc_name_middle)
            a1_tsc_name_last.AppendChild(xmla1_tsc_name_last)
            'obj---------------- 
            a1_tsc_obj_type.AppendChild(xmla1_tsc_obj_type)
            a1_tsc_obj_desc.AppendChild(xmla1_tsc_obj_desc)
            'tsc==========End==================
            'record==========Begin================== 
            a1_record_note.AppendChild(xmla1_record_note)
            'record==========End==================

            '// Save to the XML file
            'xmldoc.Save(filePath)
            Dim ansiWriter As StreamWriter
            ansiWriter = New StreamWriter(filePath, False, Encoding.Default)
            xmldoc.Save(ansiWriter)
            ansiWriter.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function AddAMLO1059node(ByVal filePath As String, ByVal idList As List(Of Integer), ByVal intLoop As Integer) As Boolean
        Dim strNAV As String = "N/A"
        Dim sOrgID As String
        Dim orgidValue As String
        Dim orgNameValue As String
        Dim orgTelValue As String
        Dim orgType As String
        Dim DOCUMENTNO, YearMonth As String
        Dim strOrg As String
        orgidValue = System.Configuration.ConfigurationManager.AppSettings("ORGID")
        orgNameValue = System.Configuration.ConfigurationManager.AppSettings("ORGNAME")
        orgTelValue = System.Configuration.ConfigurationManager.AppSettings("ORGTEL")
        orgType = System.Configuration.ConfigurationManager.AppSettings("ORGTYPE")

        sOrgID = orgType & orgidValue

        Try
            Dim i As Integer
            Dim xmldoc As XmlDocument
            xmldoc = New XmlDocument()
            Dim xmlDec As XmlDeclaration = xmldoc.CreateXmlDeclaration("1.0", "utf-8", Nothing)
            xmldoc.AppendChild(xmlDec)
            'xmldoc.Load(filePath)
            Dim parentNode As XmlElement
            parentNode = xmldoc.CreateElement("ersreport")
            parentNode.SetAttribute("version", "1.0")
            xmldoc.AppendChild(parentNode)

            Dim reportingdetail = xmldoc.CreateElement("reportingdetail")
            reportingdetail.SetAttribute("orgid", orgidValue)
            reportingdetail.SetAttribute("orgname", orgNameValue)
            parentNode.AppendChild(reportingdetail)

            clsDateFormat = New clsDateFormat

            GenDocumentNO(idList)

            Dim AMLO1059Entity = New AMLO1059Entities
            Dim qryAmlo = (From tblAmlo In AMLO1059Entity.AMLO1059 Join tblBranch In AMLO1059Entity.SBRANCHes _
                      On tblAmlo.INIT_SOL_ID Equals tblBranch.SOL_ID _
                     Group Join tblTran In AMLO1059Entity.MTSCTYPE_1_05_9 On tblAmlo.KEY_FLG Equals tblTran.TSCTYPEID
                      Into leftJoinAmlo = Group
                      From tblLeftAmlo In leftJoinAmlo.DefaultIfEmpty
                    Where idList.Contains(tblAmlo.ID)
                     Order By tblAmlo.ID
                     Select tblAmlo.KEY_FLG, tblAmlo.INIT_SOL_ID, tblAmlo.DCN_DOCUMENTNO, tblAmlo.DCN_YEARMONTH, tblAmlo.VALUE_TYPE _
                     , tblAmlo.ANOTHER_METHOD, tblAmlo.MTSCTYPE_1_05_9.TSCMETHOD, tblAmlo.MTSCTYPE_1_05_9.F_XMLPART1, tblAmlo.MTSCTYPE_1_05_9.F_XMLPART2, tblAmlo.MTSCTYPE_1_05_9.F_CUSTNO, tblAmlo.MTSCTYPE_1_05_9.F_RELATIONSHIP _
                     , tblAmlo.P2_FLG_TYPE2, tblAmlo.P2_SALUTATION2, tblAmlo.P2_CUST_FNAME2, tblAmlo.P2_CUST_MNAME2, tblAmlo.P2_CUST_LNAME2, tblAmlo.P2_NATIONALITY2 _
                     , tblAmlo.P2_OCCUPATION2_CODE, tblAmlo.P2_OCCUPATION2_DESC _
                     , tblAmlo.P2_TYPE2_HOME, tblAmlo.P2_HOME2_NO, tblAmlo.P2_HOME2_ADDRESS, tblAmlo.P2_HOME2_CITY, tblAmlo.P2_HOME2_STATE, tblAmlo.P2_HOME2_COUNTRY, tblAmlo.P2_HOME2_ZIP, tblAmlo.P2_HOME2_NATION _
                     , tblAmlo.P2_TYPE2_HPHONE, tblAmlo.P2_HOME2_PHONE, tblAmlo.P2_TYPE2_HFAX, tblAmlo.P2_HOME2_FAX _
                     , tblAmlo.P2_TYPE2_WORK, tblAmlo.P2_WORK2_NO, tblAmlo.P2_WORK2_ADDRESS, tblAmlo.P2_WORK2_CITY, tblAmlo.P2_WORK2_STATE, tblAmlo.P2_WORK2_COUNTRY, tblAmlo.P2_WORK2_ZIP, tblAmlo.P2_WORK2_NATION _
                     , tblAmlo.P2_TYPE2_WPHONE, tblAmlo.P2_WORK2_PHONE, tblAmlo.P2_TYPE2_WFAX, tblAmlo.P2_WORK2_FAX _
                     , tblAmlo.P2_TYPE2_MAIL, tblAmlo.P2_MAIL2_NO, tblAmlo.P2_MAIL2_ADDRESS, tblAmlo.P2_MAIL2_CITY, tblAmlo.P2_MAIL2_STATE, tblAmlo.P2_MAIL2_COUNTRY, tblAmlo.P2_MAIL2_ZIP, tblAmlo.P2_MAIL2_NATION _
                     , tblAmlo.P2_TYPE2_MPHONE, tblAmlo.P2_MAIL2_PHONE, tblAmlo.P2_TYPE2_MFAX, tblAmlo.P2_MAIL2_FAX, tblAmlo.P2_TYPE2_MCELL, tblAmlo.P2_MAIL2_CELL, tblAmlo.P2_TYPE2_MMAIL, tblAmlo.P2_MAIL2_EMAIL _
                     , tblAmlo.P2_CITIZEN_ID2, tblAmlo.P2_CITIZEN_OPN_BY2, tblAmlo.P2_CITIZEN_OPN2, tblAmlo.P2_CITIZEN_EXPIRED2 _
                     , tblAmlo.P2_FLG_TYPE, tblAmlo.P2_SALUTATION, tblAmlo.P2_CUST_FNAME, tblAmlo.P2_CUST_MNAME, tblAmlo.P2_CUST_LNAME, tblAmlo.P2_NATIONALITY _
                     , tblAmlo.P2_OCCUPATION_CODE, tblAmlo.P2_OCCUPATION_DESC _
                     , tblAmlo.P2_TYPE_HOME, tblAmlo.P2_HOME_NO, tblAmlo.P2_HOME_ADDRESS, tblAmlo.P2_HOME_CITY, tblAmlo.P2_HOME_STATE, tblAmlo.P2_HOME_COUNTRY, tblAmlo.P2_HOME_ZIP, tblAmlo.P2_HOME_NATION _
                     , tblAmlo.P2_TYPE_HPHONE, tblAmlo.P2_HOME_PHONE, tblAmlo.P2_TYPE_HFAX, tblAmlo.P2_HOME_FAX _
                     , tblAmlo.P2_TYPE_WORK, tblAmlo.P2_WORK_NO, tblAmlo.P2_WORK_ADDRESS, tblAmlo.P2_WORK_CITY, tblAmlo.P2_WORK_STATE, tblAmlo.P2_WORK_COUNTRY, tblAmlo.P2_WORK_ZIP, tblAmlo.P2_WORK_NATION _
                     , tblAmlo.P2_TYPE_WPHONE, tblAmlo.P2_WORK_PHONE, tblAmlo.P2_TYPE_WFAX, tblAmlo.P2_WORK_FAX _
                     , tblAmlo.P2_TYPE_MAIL, tblAmlo.P2_MAIL_NO, tblAmlo.P2_MAIL_ADDRESS, tblAmlo.P2_MAIL_CITY, tblAmlo.P2_MAIL_STATE, tblAmlo.P2_MAIL_COUNTRY, tblAmlo.P2_MAIL_ZIP, tblAmlo.P2_MAIL_NATION _
                     , tblAmlo.P2_TYPE_MPHONE, tblAmlo.P2_MAIL_PHONE, tblAmlo.P2_TYPE_MFAX, tblAmlo.P2_MAIL_FAX, tblAmlo.P2_TYPE_MCELL, tblAmlo.P2_MAIL_CELL, tblAmlo.P2_TYPE_MMAIL, tblAmlo.P2_MAIL_EMAIL _
                     , tblAmlo.P2_CITIZEN_ID, tblAmlo.P2_CITIZEN_OPN_BY, tblAmlo.P2_CITIZEN_OPN, tblAmlo.P2_CITIZEN_EXPIRED _
                     , tblAmlo.P3_TRANS_DATE, tblAmlo.P3_TRANS_TYPE, tblAmlo.P3_TRAN_CODE, tblAmlo.P3_FORACID, tblAmlo.P3_TRAN_ID, tblAmlo.P3_COMPANY_NAME _
                     , tblAmlo.P3_CUST_NAME, tblAmlo.P3_HOME_ADDRESS, tblAmlo.P3_CITIZEN_ID, tblAmlo.P3_CITIZEN_BY, tblAmlo.P3_CITIZEN_EXPIRED, tblAmlo.P3_LICENSE, tblAmlo.P3_CUST_DOB, tblAmlo.P3_BORN_PLACE _
                     , tblAmlo.P3_FORACID2, tblAmlo.P3_TRAN_ID2, tblAmlo.P3_COMPANY_NAME2 _
                     , tblAmlo.P3_CUST_NAME2, tblAmlo.P3_HOME_ADDRESS2, tblAmlo.P3_CITIZEN_ID2, tblAmlo.P3_CITIZEN_BY2, tblAmlo.P3_CITIZEN_EXPIRED2, tblAmlo.P3_LICENSE2, tblAmlo.P3_CUST_DOB2, tblAmlo.P3_BORN_PLACE2 _
                     , tblAmlo.P3_TRAN_AMT, tblAmlo.P3_THAI_BAHT _
                     , tblAmlo.FROM_ACID, tblAmlo.TO_ACID).ToList

            Dim a1_report As XmlElement
            Dim a1_reportorgdetail As XmlElement
            Dim a1_dcn As XmlElement
            Dim a1_reporttype As XmlElement

            For i = 0 To qryAmlo.Count - 1
                Dim obj = qryAmlo(i)
                DOCUMENTNO = IIf(String.IsNullOrEmpty(obj.DCN_DOCUMENTNO), "000000", obj.DCN_DOCUMENTNO)

                YearMonth = obj.DCN_YEARMONTH

                a1_report = xmldoc.CreateElement("report")

                a1_reportorgdetail = xmldoc.CreateElement("reportorgdetail")
                a1_reportorgdetail.SetAttribute("branchcode", obj.INIT_SOL_ID)
                a1_reportorgdetail.SetAttribute("orgname", orgNameValue)
                a1_reportorgdetail.SetAttribute("telno", orgTelValue)

                a1_dcn = xmldoc.CreateElement("dcn")
                a1_dcn.SetAttribute("value", "09-" & sOrgID & "-" & obj.INIT_SOL_ID & "-" & YearMonth & "-" & DOCUMENTNO)
                a1_dcn.SetAttribute("doctype", "1-05-9")
                'a1_dcn.SetAttribute("revision", XXX)
                'a1_dcn.SetAttribute("date", XXX)
                'a1_dcn.SetAttribute("refdocno", XXX)
                'a1_dcn.SetAttribute("refdoctype", XXX)

                a1_reporttype = xmldoc.CreateElement("reporttype")
                a1_reporttype.SetAttribute("value", obj.VALUE_TYPE)

                parentNode.AppendChild(a1_report)
                a1_report.AppendChild(a1_reportorgdetail)
                a1_report.AppendChild(a1_dcn)
                a1_report.AppendChild(a1_reporttype)

                '======= ส่วนที่ 1 ข้อมูลผู้ทำธุรกรรม ========
                Dim a1_person As XmlElement
                Dim a1_person_name As XmlElement
                Dim a1_person_occupation As XmlElement
                Dim a1_person_contact As XmlElement
                Dim a1_person_contact_address As XmlElement
                Dim a1_person_contact_address_othercontact As XmlElement
                Dim a1_person_contact_address_othercontact_oc As XmlElement 'มีได้มากกว่า 1
                Dim a1_person_iddoc As XmlElement

                a1_person = xmldoc.CreateElement("person")
                a1_person.SetAttribute("anothermethod", IIf(obj.ANOTHER_METHOD Is Nothing, "FALSE", obj.ANOTHER_METHOD))
                If obj.ANOTHER_METHOD = "TRUE" Then
                    a1_person.SetAttribute("am_transactionmethod", obj.ANOTHER_METHOD)
                    If obj.F_CUSTNO = "SEND" Then
                        a1_person.SetAttribute("am_customeraccno", obj.P3_FORACID)
                    ElseIf obj.F_CUSTNO = "RECEIVE" Then
                        a1_person.SetAttribute("am_customeraccno", obj.P3_FORACID2)
                    End If
                End If
                a1_person.SetAttribute("value", "TRANSACTING-PERSON")
                a1_person.SetAttribute("relationship", "SELF")
                'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                If (obj.F_XMLPART1 = "SEND") Then
                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE2)
                    If obj.P2_FLG_TYPE2 = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), strNAV, obj.P2_CUST_FNAME2))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), strNAV, obj.P2_CUST_LNAME2))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY2) Or obj.P2_NATIONALITY2 = "OTHER", "STATELESS", obj.P2_NATIONALITY2))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), "", obj.P2_CUST_LNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME2), "", obj.P2_CUST_MNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                    End If
                    a1_person.AppendChild(a1_person_name)


                    If (obj.P2_FLG_TYPE2 = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK2_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_CODE), "99", obj.P2_OCCUPATION2_CODE))
                        If (obj.P2_OCCUPATION2_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_DESC), strNAV, obj.P2_OCCUPATION2_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NO), strNAV, obj.P2_HOME2_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME2_CITY), strNAV, obj.P2_HOME2_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ADDRESS), "", obj.P2_HOME2_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME2_STATE), strNAV, obj.P2_HOME2_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME2_COUNTRY), strNAV, obj.P2_HOME2_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ZIP), strNAV, obj.P2_HOME2_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NATION), strNAV, obj.P2_HOME2_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HPHONE, obj.P2_HOME2_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HFAX, obj.P2_HOME2_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NO), strNAV, obj.P2_WORK2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK2_CITY), strNAV, obj.P2_WORK2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ADDRESS), "", obj.P2_WORK2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK2_STATE), strNAV, obj.P2_WORK2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK2_COUNTRY), strNAV, obj.P2_WORK2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ZIP), strNAV, obj.P2_WORK2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NATION), strNAV, obj.P2_WORK2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WPHONE, obj.P2_WORK2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WFAX, obj.P2_WORK2_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NO), strNAV, obj.P2_MAIL2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_CITY), strNAV, obj.P2_MAIL2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ADDRESS), "", obj.P2_MAIL2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_STATE), strNAV, obj.P2_MAIL2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_COUNTRY), strNAV, obj.P2_MAIL2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ZIP), strNAV, obj.P2_MAIL2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NATION), strNAV, obj.P2_MAIL2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MPHONE, obj.P2_MAIL2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MFAX, obj.P2_MAIL2_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MCELL, obj.P2_MAIL2_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MMAIL, obj.P2_MAIL2_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID2), strNAV, obj.P2_CITIZEN_ID2))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY2), strNAV, obj.P2_CITIZEN_OPN_BY2))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN2))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED2))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                If (obj.F_XMLPART1 = "RECEIVE") Then
                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE)
                    If obj.P2_FLG_TYPE = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), strNAV, obj.P2_CUST_FNAME))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), strNAV, obj.P2_CUST_LNAME))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY) Or obj.P2_NATIONALITY = "OTHER", "STATELESS", obj.P2_NATIONALITY))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), "", obj.P2_CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME), "", obj.P2_CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                    End If
                    a1_person.AppendChild(a1_person_name)

                    If (obj.P2_FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_CODE), "99", obj.P2_OCCUPATION_CODE))
                        If (obj.P2_OCCUPATION_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_DESC), strNAV, obj.P2_OCCUPATION_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME_NO), strNAV, obj.P2_HOME_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME_CITY), strNAV, obj.P2_HOME_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME_ADDRESS), "", obj.P2_HOME_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME_STATE), strNAV, obj.P2_HOME_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME_COUNTRY), strNAV, obj.P2_HOME_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME_ZIP), strNAV, obj.P2_HOME_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME_NATION), strNAV, obj.P2_HOME_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HPHONE, obj.P2_HOME_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HFAX, obj.P2_HOME_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK_NO), strNAV, obj.P2_WORK_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK_CITY), strNAV, obj.P2_WORK_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK_ADDRESS), "", obj.P2_WORK_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK_STATE), strNAV, obj.P2_WORK_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK_COUNTRY), strNAV, obj.P2_WORK_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK_ZIP), strNAV, obj.P2_WORK_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK_NATION), strNAV, obj.P2_WORK_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WPHONE, obj.P2_WORK_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WFAX, obj.P2_WORK_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NO), strNAV, obj.P2_MAIL_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL_CITY), strNAV, obj.P2_MAIL_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ADDRESS), "", obj.P2_MAIL_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL_STATE), strNAV, obj.P2_MAIL_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL_COUNTRY), strNAV, obj.P2_MAIL_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ZIP), strNAV, obj.P2_MAIL_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NATION), strNAV, obj.P2_MAIL_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MPHONE, obj.P2_MAIL_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MFAX, obj.P2_MAIL_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MCELL, obj.P2_MAIL_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MMAIL, obj.P2_MAIL_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID), strNAV, obj.P2_CITIZEN_ID))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY), strNAV, obj.P2_CITIZEN_OPN_BY))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                a1_report.AppendChild(a1_person)

                '======= ส่วนที่ 2 ข้อมูลผู้ร่วมทำธุรกรรม, ผู้มอบอำนาจ ========
                If (obj.F_XMLPART2 = "SEND") Then

                    a1_person = xmldoc.CreateElement("person")
                    a1_person.SetAttribute("value", "RELATED-PERSON")
                    a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                    'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE2)
                    If obj.P2_FLG_TYPE2 = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), strNAV, obj.P2_CUST_FNAME2))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), strNAV, obj.P2_CUST_LNAME2))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY2) Or obj.P2_NATIONALITY2 = "OTHER", "STATELESS", obj.P2_NATIONALITY2))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), "", obj.P2_CUST_LNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME2), "", obj.P2_CUST_MNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                        a1_person_name.SetAttribute("legalpersonid", strNAV)
                    End If
                    a1_person.AppendChild(a1_person_name)
                    a1_report.AppendChild(a1_person)

                    '=== occupation
                    If (obj.P2_FLG_TYPE2 = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK2_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_CODE), "99", obj.P2_OCCUPATION2_CODE))
                        If (obj.P2_OCCUPATION2_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_DESC), strNAV, obj.P2_OCCUPATION2_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NO), strNAV, obj.P2_HOME2_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME2_CITY), strNAV, obj.P2_HOME2_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ADDRESS), "", obj.P2_HOME2_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME2_STATE), strNAV, obj.P2_HOME2_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME2_COUNTRY), strNAV, obj.P2_HOME2_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ZIP), strNAV, obj.P2_HOME2_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NATION), strNAV, obj.P2_HOME2_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HPHONE, obj.P2_HOME2_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HFAX, obj.P2_HOME2_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NO), strNAV, obj.P2_WORK2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK2_CITY), strNAV, obj.P2_WORK2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ADDRESS), "", obj.P2_WORK2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK2_STATE), strNAV, obj.P2_WORK2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK2_COUNTRY), strNAV, obj.P2_WORK2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ZIP), strNAV, obj.P2_WORK2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NATION), strNAV, obj.P2_WORK2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WPHONE, obj.P2_WORK2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WFAX, obj.P2_WORK2_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NO), strNAV, obj.P2_MAIL2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_CITY), strNAV, obj.P2_MAIL2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ADDRESS), "", obj.P2_MAIL2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_STATE), strNAV, obj.P2_MAIL2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_COUNTRY), strNAV, obj.P2_MAIL2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ZIP), strNAV, obj.P2_MAIL2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NATION), strNAV, obj.P2_MAIL2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MPHONE, obj.P2_MAIL2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MFAX, obj.P2_MAIL2_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MCELL, obj.P2_MAIL2_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MMAIL, obj.P2_MAIL2_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID2), strNAV, obj.P2_CITIZEN_ID2))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY2), strNAV, obj.P2_CITIZEN_OPN_BY2))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN2))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED2))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                If (obj.F_XMLPART2 = "RECEIVE") Then

                    a1_person = xmldoc.CreateElement("person")
                    a1_person.SetAttribute("value", "RELATED-PERSON")
                    a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                    'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE)
                    If obj.P2_FLG_TYPE = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), strNAV, obj.P2_CUST_FNAME))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), strNAV, obj.P2_CUST_LNAME))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY) Or obj.P2_NATIONALITY = "OTHER", "STATELESS", obj.P2_NATIONALITY))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), "", obj.P2_CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME), "", obj.P2_CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), "", obj.P2_CUST_LNAME)
                        a1_person_name.SetAttribute("firstname", legalName)
                        a1_person_name.SetAttribute("legalpersonid", strNAV)
                    End If
                    a1_person.AppendChild(a1_person_name)
                    a1_report.AppendChild(a1_person)

                    '=== occupation
                    If (obj.P2_FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_CODE), "99", obj.P2_OCCUPATION_CODE))
                        If (obj.P2_OCCUPATION_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_DESC), strNAV, obj.P2_OCCUPATION_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If


                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME_NO), strNAV, obj.P2_HOME_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME_CITY), strNAV, obj.P2_HOME_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME_ADDRESS), "", obj.P2_HOME_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME_STATE), strNAV, obj.P2_HOME_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME_COUNTRY), strNAV, obj.P2_HOME_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME_ZIP), strNAV, obj.P2_HOME_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME_NATION), strNAV, obj.P2_HOME_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HPHONE, obj.P2_HOME_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HFAX, obj.P2_HOME_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK_NO), strNAV, obj.P2_WORK_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK_CITY), strNAV, obj.P2_WORK_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK_ADDRESS), "", obj.P2_WORK_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK_STATE), strNAV, obj.P2_WORK_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK_COUNTRY), strNAV, obj.P2_WORK_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK_ZIP), strNAV, obj.P2_WORK_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK_NATION), strNAV, obj.P2_WORK_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WPHONE, obj.P2_WORK_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WFAX, obj.P2_WORK_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NO), strNAV, obj.P2_MAIL_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL_CITY), strNAV, obj.P2_MAIL_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ADDRESS), "", obj.P2_MAIL_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL_STATE), strNAV, obj.P2_MAIL_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL_COUNTRY), strNAV, obj.P2_MAIL_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ZIP), strNAV, obj.P2_MAIL_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NATION), strNAV, obj.P2_MAIL_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MPHONE, obj.P2_MAIL_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MFAX, obj.P2_MAIL_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MCELL, obj.P2_MAIL_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MMAIL, obj.P2_MAIL_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID), strNAV, obj.P2_CITIZEN_ID))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY), strNAV, obj.P2_CITIZEN_OPN_BY))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                '======= ส่วนที่ 3 ข้อเท็จจริงเกี่ยวกับการทำธุรกรรม ========
                Dim a1_tsc As XmlElement
                Dim a1_tsc_tscentry As XmlElement 'ระบุได้มากกว่า 1
                Dim a1_tsc_tscentry_typeoftsc As XmlElement
                Dim a1_tsc_tscentry_transferdetail As XmlElement
                Dim a1_tsc_tscentry_amount As XmlElement
                Dim a1_tsc_totalamount As XmlElement
                Dim a1_tsc_benfperson As XmlElement
                Dim a1_tsc_objective As XmlElement

                a1_tsc = xmldoc.CreateElement("tsc")
                a1_tsc.SetAttribute("date", FormatDate(obj.P3_TRANS_DATE))

                a1_tsc_tscentry = xmldoc.CreateElement("tscentry")

                a1_tsc_tscentry_typeoftsc = xmldoc.CreateElement("typeoftsc")
                a1_tsc_tscentry_typeoftsc.SetAttribute("transtype", IIf(String.IsNullOrEmpty(obj.P3_TRANS_TYPE), strNAV, obj.P3_TRANS_TYPE))
                a1_tsc_tscentry_typeoftsc.SetAttribute("type", IIf(String.IsNullOrEmpty(obj.P3_TRAN_CODE), strNAV, obj.P3_TRAN_CODE))
                If obj.P3_TRAN_CODE = "OTHER" Then
                    a1_tsc_tscentry_typeoftsc.SetAttribute("desc", "INBK")
                End If
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_typeoftsc)


                a1_tsc_tscentry_transferdetail = xmldoc.CreateElement("transferdetail")
                'ผู้โอน
                a1_tsc_tscentry_transferdetail.SetAttribute("sendaccountno", obj.P3_FORACID)
                If (String.IsNullOrEmpty(obj.P3_FORACID)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendrefno", obj.P3_TRAN_ID)
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("sendfullname", IIf(String.IsNullOrEmpty(obj.P3_CUST_NAME), strNAV, obj.P3_CUST_NAME))

                If obj.KEY_FLG = "1" Or obj.KEY_FLG = "2" Or obj.KEY_FLG = "5" Or obj.KEY_FLG = "6" Or obj.KEY_FLG = "7" Or obj.KEY_FLG = "9" Then
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME) Or obj.P3_COMPANY_NAME = "NAV", "ธนาคารอาคารสงเคราะห์", obj.P3_COMPANY_NAME)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", strOrg)
                ElseIf obj.KEY_FLG = "8" Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", "ธนาคารแห่งประเทศไทย")
                Else
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME), "NAV", obj.P3_COMPANY_NAME)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", strOrg)
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("sendorgcountry", "TH")
                a1_tsc_tscentry_transferdetail.SetAttribute("sendaddress", obj.P3_HOME_ADDRESS)
                'a1_tsc_tscentry_transferdetail.SetAttribute("sendcontactaddress", XXX)
                If (String.IsNullOrEmpty(obj.P3_HOME_ADDRESS)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidtype", obj.P3_LICENSE)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidno", obj.P3_CITIZEN_ID)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidissuer", obj.P3_CITIZEN_BY)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidexpiredate", FormatDate(obj.P3_CITIZEN_EXPIRED))
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("senddateofbirth", FormatDate(obj.P3_CUST_DOB))
                a1_tsc_tscentry_transferdetail.SetAttribute("sendplaceofbirth", obj.P3_BORN_PLACE)
                'ผู้รับ
                a1_tsc_tscentry_transferdetail.SetAttribute("recaccountno", IIf(String.IsNullOrEmpty(obj.P3_FORACID2), strNAV, obj.P3_FORACID2))
                If (String.IsNullOrEmpty(obj.P3_FORACID)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("recrefno", obj.P3_TRAN_ID2)
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("recfullname", IIf(String.IsNullOrEmpty(obj.P3_CUST_NAME2), strNAV, obj.P3_CUST_NAME2))

                If obj.KEY_FLG = "3" Or obj.KEY_FLG = "4" Or obj.KEY_FLG = "5" _
                    Or obj.KEY_FLG = "6" Or obj.KEY_FLG = "7" Or obj.KEY_FLG = "8" _
                    Or obj.KEY_FLG = "9" Then
                    strOrg = IIf(String.IsNullOrEmpty("P3_COMPANY_NAME2") Or obj.P3_COMPANY_NAME2 = "NAV", "ธนาคารอาคารสงเคราะห์", obj.P3_COMPANY_NAME2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recorg", strOrg)
                Else
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME2), "NAV", obj.P3_COMPANY_NAME2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recorg", strOrg)
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("recorgcountry", "TH")
                a1_tsc_tscentry_transferdetail.SetAttribute("recaddress", IIf(String.IsNullOrEmpty(obj.P3_HOME_ADDRESS2), strNAV, obj.P3_HOME_ADDRESS2))
                'a1_tsc_tscentry_transferdetail.SetAttribute("reccontactaddress", XXX)
                If (String.IsNullOrEmpty(obj.P3_HOME_ADDRESS2)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidtype", obj.P3_LICENSE2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidno", obj.P3_CITIZEN_ID2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidissuer", obj.P3_CITIZEN_BY2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidexpiredate", FormatDate(obj.P3_CITIZEN_EXPIRED2))
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("recdateofbirth", FormatDate(obj.P3_CUST_DOB2))
                a1_tsc_tscentry_transferdetail.SetAttribute("recplaceofbirth", obj.P3_BORN_PLACE2)
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_transferdetail)


                a1_tsc_tscentry_amount = xmldoc.CreateElement("amount")
                a1_tsc_tscentry_amount.SetAttribute("valueinbaht", String.Format("{0:F2}", obj.P3_TRAN_AMT))
                a1_tsc_tscentry_amount.SetAttribute("valueinbahttxt", obj.P3_THAI_BAHT)
                'ธอส ไม่มีเงินต่างประเทศ
                'a1_tsc_tscentry_amount.SetAttribute("value", XXX)
                'a1_tsc_tscentry_amount.SetAttribute("curr", XXX)
                'a1_tsc_tscentry_amount.SetAttribute("exchangerate", XXX)
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_amount)

                a1_tsc_totalamount = xmldoc.CreateElement("totalamount")
                a1_tsc_totalamount.SetAttribute("valueinbaht", String.Format("{0:F2}", obj.P3_TRAN_AMT))
                a1_tsc_totalamount.SetAttribute("valueinbahttxt", obj.P3_THAI_BAHT)
                a1_tsc.AppendChild(a1_tsc_totalamount)

                'a1_tsc_benfperson = xmldoc.CreateElement("benfperson")
                'a1_tsc_benfperson.SetAttribute("firstname", XXX)
                'a1_tsc_benfperson.SetAttribute("middlename", XXX)
                'a1_tsc_benfperson.SetAttribute("lastname", XXX)

                a1_tsc_objective = xmldoc.CreateElement("objective")
                a1_tsc_objective.InnerText = "เพื่อทำธุรกรรม"
                'a1_tsc_objective.SetAttribute("type", XXX)
                a1_tsc.AppendChild(a1_tsc_objective)

                a1_tsc.AppendChild(a1_tsc_tscentry)
                a1_report.AppendChild(a1_tsc)

                '======= ส่วนที่ 4 วันที่บันทึกรายงาน ========
                Dim a1_record As XmlElement
                a1_record = xmldoc.CreateElement("record")
                a1_record.SetAttribute("date", FormatDate(Date.Today))
                a1_report.AppendChild(a1_record)

            Next

            '// Save to the XML file
            'xmldoc.Save(filePath)
            Dim ansiWriter As StreamWriter
            ansiWriter = New StreamWriter(filePath, False, Encoding.UTF8)
            xmldoc.Save(ansiWriter)

            ansiWriter.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function AddAMLO1059nodeWithAcid(ByVal filePath As String, ByVal idList As List(Of Integer), ByVal intLoop As Integer) As Boolean
        Dim strNAV As String = "N/A"
        Dim sOrgID As String
        Dim orgidValue As String
        Dim orgNameValue As String
        Dim orgTelValue As String
        Dim orgType As String
        Dim DOCUMENTNO, YearMonth As String
        Dim strOrg As String
        orgidValue = System.Configuration.ConfigurationManager.AppSettings("ORGID")
        orgNameValue = System.Configuration.ConfigurationManager.AppSettings("ORGNAME")
        orgTelValue = System.Configuration.ConfigurationManager.AppSettings("ORGTEL")
        orgType = System.Configuration.ConfigurationManager.AppSettings("ORGTYPE")

        sOrgID = orgType & orgidValue

        Try
            Dim i As Integer
            Dim xmldoc As XmlDocument
            xmldoc = New XmlDocument()
            Dim xmlDec As XmlDeclaration = xmldoc.CreateXmlDeclaration("1.0", "utf-8", Nothing)
            xmldoc.AppendChild(xmlDec)
            'xmldoc.Load(filePath)
            Dim parentNode As XmlElement
            parentNode = xmldoc.CreateElement("ersreport")
            parentNode.SetAttribute("version", "1.0")
            xmldoc.AppendChild(parentNode)

            Dim reportingdetail = xmldoc.CreateElement("reportingdetail")
            reportingdetail.SetAttribute("orgid", orgidValue)
            reportingdetail.SetAttribute("orgname", orgNameValue)
            parentNode.AppendChild(reportingdetail)

            clsDateFormat = New clsDateFormat

            GenDocumentNO(idList)

            Dim AMLO1059Entity = New AMLO1059Entities
            Dim qryAmlo = (From tblAmlo In AMLO1059Entity.AMLO1059 Join tblBranch In AMLO1059Entity.SBRANCHes _
                      On tblAmlo.INIT_SOL_ID Equals tblBranch.SOL_ID _
                     Group Join tblTran In AMLO1059Entity.MTSCTYPE_1_05_9 On tblAmlo.KEY_FLG Equals tblTran.TSCTYPEID
                      Into leftJoinAmlo = Group
                      From tblLeftAmlo In leftJoinAmlo.DefaultIfEmpty
                    Where idList.Contains(tblAmlo.ID)
                     Order By tblAmlo.ID
                     Select tblAmlo.KEY_FLG, tblAmlo.INIT_SOL_ID, tblAmlo.DCN_DOCUMENTNO, tblAmlo.DCN_YEARMONTH, tblAmlo.VALUE_TYPE _
                     , tblAmlo.ANOTHER_METHOD, tblAmlo.MTSCTYPE_1_05_9.TSCMETHOD, tblAmlo.MTSCTYPE_1_05_9.F_XMLPART1, tblAmlo.MTSCTYPE_1_05_9.F_XMLPART2, tblAmlo.MTSCTYPE_1_05_9.F_CUSTNO, tblAmlo.MTSCTYPE_1_05_9.F_RELATIONSHIP, tblAmlo.MTSCTYPE_1_05_9.F_COTRAN _
                     , tblAmlo.P2_FLG_TYPE2, tblAmlo.P2_SALUTATION2, tblAmlo.P2_CUST_FNAME2, tblAmlo.P2_CUST_MNAME2, tblAmlo.P2_CUST_LNAME2, tblAmlo.P2_NATIONALITY2 _
                     , tblAmlo.P2_OCCUPATION2_CODE, tblAmlo.P2_OCCUPATION2_DESC _
                     , tblAmlo.P2_TYPE2_HOME, tblAmlo.P2_HOME2_NO, tblAmlo.P2_HOME2_ADDRESS, tblAmlo.P2_HOME2_CITY, tblAmlo.P2_HOME2_STATE, tblAmlo.P2_HOME2_COUNTRY, tblAmlo.P2_HOME2_ZIP, tblAmlo.P2_HOME2_NATION _
                     , tblAmlo.P2_TYPE2_HPHONE, tblAmlo.P2_HOME2_PHONE, tblAmlo.P2_TYPE2_HFAX, tblAmlo.P2_HOME2_FAX _
                     , tblAmlo.P2_TYPE2_WORK, tblAmlo.P2_WORK2_NO, tblAmlo.P2_WORK2_ADDRESS, tblAmlo.P2_WORK2_CITY, tblAmlo.P2_WORK2_STATE, tblAmlo.P2_WORK2_COUNTRY, tblAmlo.P2_WORK2_ZIP, tblAmlo.P2_WORK2_NATION _
                     , tblAmlo.P2_TYPE2_WPHONE, tblAmlo.P2_WORK2_PHONE, tblAmlo.P2_TYPE2_WFAX, tblAmlo.P2_WORK2_FAX _
                     , tblAmlo.P2_TYPE2_MAIL, tblAmlo.P2_MAIL2_NO, tblAmlo.P2_MAIL2_ADDRESS, tblAmlo.P2_MAIL2_CITY, tblAmlo.P2_MAIL2_STATE, tblAmlo.P2_MAIL2_COUNTRY, tblAmlo.P2_MAIL2_ZIP, tblAmlo.P2_MAIL2_NATION _
                     , tblAmlo.P2_TYPE2_MPHONE, tblAmlo.P2_MAIL2_PHONE, tblAmlo.P2_TYPE2_MFAX, tblAmlo.P2_MAIL2_FAX, tblAmlo.P2_TYPE2_MCELL, tblAmlo.P2_MAIL2_CELL, tblAmlo.P2_TYPE2_MMAIL, tblAmlo.P2_MAIL2_EMAIL _
                     , tblAmlo.P2_CITIZEN_ID2, tblAmlo.P2_CITIZEN_OPN_BY2, tblAmlo.P2_CITIZEN_OPN2, tblAmlo.P2_CITIZEN_EXPIRED2 _
                     , tblAmlo.P2_FLG_TYPE, tblAmlo.P2_SALUTATION, tblAmlo.P2_CUST_FNAME, tblAmlo.P2_CUST_MNAME, tblAmlo.P2_CUST_LNAME, tblAmlo.P2_NATIONALITY _
                     , tblAmlo.P2_OCCUPATION_CODE, tblAmlo.P2_OCCUPATION_DESC _
                     , tblAmlo.P2_TYPE_HOME, tblAmlo.P2_HOME_NO, tblAmlo.P2_HOME_ADDRESS, tblAmlo.P2_HOME_CITY, tblAmlo.P2_HOME_STATE, tblAmlo.P2_HOME_COUNTRY, tblAmlo.P2_HOME_ZIP, tblAmlo.P2_HOME_NATION _
                     , tblAmlo.P2_TYPE_HPHONE, tblAmlo.P2_HOME_PHONE, tblAmlo.P2_TYPE_HFAX, tblAmlo.P2_HOME_FAX _
                     , tblAmlo.P2_TYPE_WORK, tblAmlo.P2_WORK_NO, tblAmlo.P2_WORK_ADDRESS, tblAmlo.P2_WORK_CITY, tblAmlo.P2_WORK_STATE, tblAmlo.P2_WORK_COUNTRY, tblAmlo.P2_WORK_ZIP, tblAmlo.P2_WORK_NATION _
                     , tblAmlo.P2_TYPE_WPHONE, tblAmlo.P2_WORK_PHONE, tblAmlo.P2_TYPE_WFAX, tblAmlo.P2_WORK_FAX _
                     , tblAmlo.P2_TYPE_MAIL, tblAmlo.P2_MAIL_NO, tblAmlo.P2_MAIL_ADDRESS, tblAmlo.P2_MAIL_CITY, tblAmlo.P2_MAIL_STATE, tblAmlo.P2_MAIL_COUNTRY, tblAmlo.P2_MAIL_ZIP, tblAmlo.P2_MAIL_NATION _
                     , tblAmlo.P2_TYPE_MPHONE, tblAmlo.P2_MAIL_PHONE, tblAmlo.P2_TYPE_MFAX, tblAmlo.P2_MAIL_FAX, tblAmlo.P2_TYPE_MCELL, tblAmlo.P2_MAIL_CELL, tblAmlo.P2_TYPE_MMAIL, tblAmlo.P2_MAIL_EMAIL _
                     , tblAmlo.P2_CITIZEN_ID, tblAmlo.P2_CITIZEN_OPN_BY, tblAmlo.P2_CITIZEN_OPN, tblAmlo.P2_CITIZEN_EXPIRED _
                     , tblAmlo.P3_TRANS_DATE, tblAmlo.P3_TRANS_TYPE, tblAmlo.P3_TRAN_CODE, tblAmlo.P3_FORACID, tblAmlo.P3_TRAN_ID, tblAmlo.P3_COMPANY_NAME _
                     , tblAmlo.P3_CUST_NAME, tblAmlo.P3_HOME_ADDRESS, tblAmlo.P3_CITIZEN_ID, tblAmlo.P3_CITIZEN_BY, tblAmlo.P3_CITIZEN_EXPIRED, tblAmlo.P3_LICENSE, tblAmlo.P3_CUST_DOB, tblAmlo.P3_BORN_PLACE _
                     , tblAmlo.P3_FORACID2, tblAmlo.P3_TRAN_ID2, tblAmlo.P3_COMPANY_NAME2 _
                     , tblAmlo.P3_CUST_NAME2, tblAmlo.P3_HOME_ADDRESS2, tblAmlo.P3_CITIZEN_ID2, tblAmlo.P3_CITIZEN_BY2, tblAmlo.P3_CITIZEN_EXPIRED2, tblAmlo.P3_LICENSE2, tblAmlo.P3_CUST_DOB2, tblAmlo.P3_BORN_PLACE2 _
                     , tblAmlo.P3_TRAN_AMT, tblAmlo.P3_THAI_BAHT _
                     , tblAmlo.FROM_ACID, tblAmlo.TO_ACID).ToList

            Dim a1_report As XmlElement
            Dim a1_reportorgdetail As XmlElement
            Dim a1_dcn As XmlElement
            Dim a1_reporttype As XmlElement

            For i = 0 To qryAmlo.Count - 1
                Dim obj = qryAmlo(i)
                DOCUMENTNO = IIf(String.IsNullOrEmpty(obj.DCN_DOCUMENTNO), "000000", obj.DCN_DOCUMENTNO)

                YearMonth = obj.DCN_YEARMONTH

                a1_report = xmldoc.CreateElement("report")

                a1_reportorgdetail = xmldoc.CreateElement("reportorgdetail")
                a1_reportorgdetail.SetAttribute("branchcode", obj.INIT_SOL_ID)
                a1_reportorgdetail.SetAttribute("orgname", orgNameValue)
                a1_reportorgdetail.SetAttribute("telno", orgTelValue)

                a1_dcn = xmldoc.CreateElement("dcn")
                a1_dcn.SetAttribute("value", "09-" & sOrgID & "-" & obj.INIT_SOL_ID & "-" & YearMonth & "-" & DOCUMENTNO)
                a1_dcn.SetAttribute("doctype", "1-05-9")
                'a1_dcn.SetAttribute("revision", XXX)
                'a1_dcn.SetAttribute("date", XXX)
                'a1_dcn.SetAttribute("refdocno", XXX)
                'a1_dcn.SetAttribute("refdoctype", XXX)

                a1_reporttype = xmldoc.CreateElement("reporttype")
                a1_reporttype.SetAttribute("value", obj.VALUE_TYPE)

                parentNode.AppendChild(a1_report)
                a1_report.AppendChild(a1_reportorgdetail)
                a1_report.AppendChild(a1_dcn)
                a1_report.AppendChild(a1_reporttype)

                '======= ส่วนที่ 1 ข้อมูลผู้ทำธุรกรรม ========
                Dim a1_person As XmlElement
                Dim a1_person_name As XmlElement
                Dim a1_person_occupation As XmlElement
                Dim a1_person_contact As XmlElement
                Dim a1_person_contact_address As XmlElement
                Dim a1_person_contact_address_othercontact As XmlElement
                Dim a1_person_contact_address_othercontact_oc As XmlElement 'มีได้มากกว่า 1
                Dim a1_person_iddoc As XmlElement

                a1_person = xmldoc.CreateElement("person")
                a1_person.SetAttribute("anothermethod", IIf(obj.ANOTHER_METHOD Is Nothing, "FALSE", obj.ANOTHER_METHOD))
                If obj.ANOTHER_METHOD = "TRUE" Then
                    a1_person.SetAttribute("am_transactionmethod", obj.ANOTHER_METHOD)
                    If obj.F_CUSTNO = "SEND" Then
                        a1_person.SetAttribute("am_customeraccno", obj.P3_FORACID)
                    ElseIf obj.F_CUSTNO = "RECEIVE" Then
                        a1_person.SetAttribute("am_customeraccno", obj.P3_FORACID2)
                    End If
                End If
                a1_person.SetAttribute("value", "TRANSACTING-PERSON")
                a1_person.SetAttribute("relationship", "SELF")
                'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                If (obj.F_XMLPART1 = "SEND") Then

                    ''===================== ACID
                    'Dim qryAcidFrom = (From tblAmlo In AMLO1059Entity.AMLO1059_ACID_FROM
                    '                   Where tblAmlo.TRAN_DATE = obj.P3_TRANS_DATE And tblAmlo.ACID = obj.FROM_ACID)
                    'For Each acid As AMLO1059_ACID_FROM In qryAcidFrom
                    '    a1_person_name = xmldoc.CreateElement("name")
                    '    a1_person_name.SetAttribute("type", acid.FLG_TYPE)
                    '    If obj.P2_FLG_TYPE2 = "PERSON" Then
                    '        a1_person_name.SetAttribute("title", acid.SALUTATION)
                    '        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(acid.CUST_FNAME), strNAV, acid.CUST_FNAME))
                    '        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                    '        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(acid.CUST_LNAME), strNAV, acid.CUST_LNAME))
                    '        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                    '        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(acid.NATIONALITY) Or acid.NATIONALITY = "OTHER", "STATELESS", acid.NATIONALITY))
                    '    Else
                    '        a1_person_name.SetAttribute("title", acid.SALUTATION)
                    '        Dim legalName = IIf(String.IsNullOrEmpty(acid.CUST_FNAME), "", acid.CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_MNAME), "", acid.CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_LNAME), "", acid.CUST_LNAME)
                    '        a1_person_name.SetAttribute("firstname", legalName)
                    '    End If
                    '    a1_person.AppendChild(a1_person_name)


                    '    If (acid.FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(acid.WORK_NO)) Then
                    '        a1_person_occupation = xmldoc.CreateElement("occupation")
                    '        a1_person_occupation.SetAttribute("companyname", strNAV)
                    '        'a1_person_occupation.SetAttribute("businesstype", XXX)
                    '        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                    '        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(acid.OCCUPATION_CODE), "99", acid.OCCUPATION_CODE))
                    '        If (acid.OCCUPATION_CODE = "99") Then
                    '            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(acid.OCCUPATION_DESC), strNAV, acid.OCCUPATION_DESC))
                    '        End If
                    '        a1_person.AppendChild(a1_person_occupation)
                    '    End If

                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_HOME)
                    '    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    '    a1_person_contact_address = xmldoc.CreateElement("address")
                    '    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.HOME_NO), strNAV, acid.HOME_NO))
                    '    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.HOME_CITY), strNAV, acid.HOME_CITY))
                    '    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.HOME_ADDRESS), "", acid.HOME_ADDRESS))
                    '    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.HOME_STATE), strNAV, acid.HOME_STATE))
                    '    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.HOME_COUNTRY), strNAV, acid.HOME_COUNTRY))
                    '    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.HOME_ZIP), strNAV, acid.HOME_ZIP))
                    '    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.HOME_NATION), strNAV, acid.HOME_NATION))

                    '    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    '    'a1_person_contact_address_othercontact_oc
                    '    AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HPHONE, acid.HOME_PHONE)
                    '    AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HFAX, acid.HOME_FAX)
                    '    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    '    a1_person.AppendChild(a1_person_contact)
                    '    a1_person_contact.AppendChild(a1_person_contact_address)
                    '    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    '    'ที่อยุ่ที่ทำงาน
                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_WORK)
                    '    If String.IsNullOrEmpty(acid.WORK_NO) Then
                    '        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    '    Else
                    '        a1_person_contact_address = xmldoc.CreateElement("address")
                    '        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.WORK_NO), strNAV, acid.WORK_NO))
                    '        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.WORK_CITY), strNAV, acid.WORK_CITY))
                    '        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.WORK_ADDRESS), "", acid.WORK_ADDRESS))
                    '        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.WORK_STATE), strNAV, acid.WORK_STATE))
                    '        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.WORK_COUNTRY), strNAV, acid.WORK_COUNTRY))
                    '        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.WORK_ZIP), strNAV, acid.WORK_ZIP))
                    '        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.WORK_NATION), strNAV, acid.WORK_NATION))

                    '        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WPHONE, acid.WORK_PHONE)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WFAX, acid.WORK_FAX)

                    '        a1_person_contact.AppendChild(a1_person_contact_address)
                    '        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    '    End If
                    '    a1_person.AppendChild(a1_person_contact)


                    '    'ที่อยู่ที่ติดต่อ
                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_MAIL)
                    '    If String.IsNullOrEmpty(acid.MAIL_NO) Then
                    '        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    '    Else
                    '        a1_person_contact_address = xmldoc.CreateElement("address")
                    '        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.MAIL_NO), strNAV, acid.MAIL_NO))
                    '        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.MAIL_CITY), strNAV, acid.MAIL_CITY))
                    '        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.MAIL_ADDRESS), "", acid.MAIL_ADDRESS))
                    '        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.MAIL_STATE), strNAV, acid.MAIL_STATE))
                    '        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.MAIL_COUNTRY), strNAV, acid.MAIL_COUNTRY))
                    '        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.MAIL_ZIP), strNAV, acid.MAIL_ZIP))
                    '        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.MAIL_NATION), strNAV, acid.MAIL_NATION))

                    '        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MPHONE, acid.MAIL_PHONE)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MFAX, acid.MAIL_FAX)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MCELL, acid.MAIL_CELL)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MMAIL, acid.MAIL_EMAIL)

                    '        a1_person_contact.AppendChild(a1_person_contact_address)
                    '        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    '    End If
                    '    a1_person.AppendChild(a1_person_contact)

                    '    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    '    a1_person_iddoc.SetAttribute("type", "99")
                    '    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    '    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(acid.CITIZEN_ID), strNAV, acid.CITIZEN_ID))
                    '    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(acid.CITIZEN_OPN_BY), strNAV, acid.CITIZEN_OPN_BY))
                    '    a1_person_iddoc.SetAttribute("issuedate", FormatDate(acid.CITIZEN_OPN))
                    '    a1_person_iddoc.SetAttribute("expiredate", FormatDate(acid.CITIZEN_EXPIRED))
                    '    a1_person.AppendChild(a1_person_iddoc)
                    '    a1_report.AppendChild(a1_person)
                    'Next

                    ''===================== END ACID
                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE2)
                    If obj.P2_FLG_TYPE2 = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), strNAV, obj.P2_CUST_FNAME2))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), strNAV, obj.P2_CUST_LNAME2))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY2) Or obj.P2_NATIONALITY2 = "OTHER", "STATELESS", obj.P2_NATIONALITY2))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), "", obj.P2_CUST_LNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME2), "", obj.P2_CUST_MNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                    End If
                    a1_person.AppendChild(a1_person_name)


                    If (obj.P2_FLG_TYPE2 = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK2_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_CODE), "99", obj.P2_OCCUPATION2_CODE))
                        If (obj.P2_OCCUPATION2_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_DESC), strNAV, obj.P2_OCCUPATION2_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NO), strNAV, obj.P2_HOME2_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME2_CITY), strNAV, obj.P2_HOME2_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ADDRESS), "", obj.P2_HOME2_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME2_STATE), strNAV, obj.P2_HOME2_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME2_COUNTRY), strNAV, obj.P2_HOME2_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ZIP), strNAV, obj.P2_HOME2_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NATION), strNAV, obj.P2_HOME2_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HPHONE, obj.P2_HOME2_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HFAX, obj.P2_HOME2_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NO), strNAV, obj.P2_WORK2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK2_CITY), strNAV, obj.P2_WORK2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ADDRESS), "", obj.P2_WORK2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK2_STATE), strNAV, obj.P2_WORK2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK2_COUNTRY), strNAV, obj.P2_WORK2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ZIP), strNAV, obj.P2_WORK2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NATION), strNAV, obj.P2_WORK2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WPHONE, obj.P2_WORK2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WFAX, obj.P2_WORK2_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NO), strNAV, obj.P2_MAIL2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_CITY), strNAV, obj.P2_MAIL2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ADDRESS), "", obj.P2_MAIL2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_STATE), strNAV, obj.P2_MAIL2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_COUNTRY), strNAV, obj.P2_MAIL2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ZIP), strNAV, obj.P2_MAIL2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NATION), strNAV, obj.P2_MAIL2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MPHONE, obj.P2_MAIL2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MFAX, obj.P2_MAIL2_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MCELL, obj.P2_MAIL2_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MMAIL, obj.P2_MAIL2_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID2), strNAV, obj.P2_CITIZEN_ID2))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY2), strNAV, obj.P2_CITIZEN_OPN_BY2))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN2))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED2))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                If (obj.F_XMLPART1 = "RECEIVE") Then

                    ''===================== ACID
                    'Dim qryAcidTo = (From tblAmlo In AMLO1059Entity.AMLO1059_ACID_TO
                    '                   Where tblAmlo.TRAN_DATE = obj.P3_TRANS_DATE And tblAmlo.ACID = obj.TO_ACID)
                    'For Each acid As AMLO1059_ACID_TO In qryAcidTo
                    '    a1_person_name = xmldoc.CreateElement("name")
                    '    a1_person_name.SetAttribute("type", acid.FLG_TYPE)
                    '    If obj.P2_FLG_TYPE2 = "PERSON" Then
                    '        a1_person_name.SetAttribute("title", acid.SALUTATION)
                    '        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(acid.CUST_FNAME), strNAV, acid.CUST_FNAME))
                    '        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                    '        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(acid.CUST_LNAME), strNAV, acid.CUST_LNAME))
                    '        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                    '        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(acid.NATIONALITY) Or acid.NATIONALITY = "OTHER", "STATELESS", acid.NATIONALITY))
                    '    Else
                    '        a1_person_name.SetAttribute("title", acid.SALUTATION)
                    '        Dim legalName = IIf(String.IsNullOrEmpty(acid.CUST_FNAME), "", acid.CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_MNAME), "", acid.CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_LNAME), "", acid.CUST_LNAME)
                    '        a1_person_name.SetAttribute("firstname", legalName)
                    '    End If
                    '    a1_person.AppendChild(a1_person_name)


                    '    If (acid.FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(acid.WORK_NO)) Then
                    '        a1_person_occupation = xmldoc.CreateElement("occupation")
                    '        a1_person_occupation.SetAttribute("companyname", strNAV)
                    '        'a1_person_occupation.SetAttribute("businesstype", XXX)
                    '        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                    '        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(acid.OCCUPATION_CODE), "99", acid.OCCUPATION_CODE))
                    '        If (acid.OCCUPATION_CODE = "99") Then
                    '            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(acid.OCCUPATION_DESC), strNAV, acid.OCCUPATION_DESC))
                    '        End If
                    '        a1_person.AppendChild(a1_person_occupation)
                    '    End If

                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_HOME)
                    '    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    '    a1_person_contact_address = xmldoc.CreateElement("address")
                    '    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.HOME_NO), strNAV, acid.HOME_NO))
                    '    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.HOME_CITY), strNAV, acid.HOME_CITY))
                    '    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.HOME_ADDRESS), "", acid.HOME_ADDRESS))
                    '    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.HOME_STATE), strNAV, acid.HOME_STATE))
                    '    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.HOME_COUNTRY), strNAV, acid.HOME_COUNTRY))
                    '    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.HOME_ZIP), strNAV, acid.HOME_ZIP))
                    '    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.HOME_NATION), strNAV, acid.HOME_NATION))

                    '    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    '    'a1_person_contact_address_othercontact_oc
                    '    AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HPHONE, acid.HOME_PHONE)
                    '    AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HFAX, acid.HOME_FAX)
                    '    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    '    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    '    a1_person.AppendChild(a1_person_contact)
                    '    a1_person_contact.AppendChild(a1_person_contact_address)
                    '    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    '    'ที่อยุ่ที่ทำงาน
                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_WORK)
                    '    If String.IsNullOrEmpty(acid.WORK_NO) Then
                    '        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    '    Else
                    '        a1_person_contact_address = xmldoc.CreateElement("address")
                    '        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.WORK_NO), strNAV, acid.WORK_NO))
                    '        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.WORK_CITY), strNAV, acid.WORK_CITY))
                    '        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.WORK_ADDRESS), "", acid.WORK_ADDRESS))
                    '        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.WORK_STATE), strNAV, acid.WORK_STATE))
                    '        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.WORK_COUNTRY), strNAV, acid.WORK_COUNTRY))
                    '        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.WORK_ZIP), strNAV, acid.WORK_ZIP))
                    '        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.WORK_NATION), strNAV, acid.WORK_NATION))

                    '        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WPHONE, acid.WORK_PHONE)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WFAX, acid.WORK_FAX)

                    '        a1_person_contact.AppendChild(a1_person_contact_address)
                    '        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    '    End If
                    '    a1_person.AppendChild(a1_person_contact)


                    '    'ที่อยู่ที่ติดต่อ
                    '    a1_person_contact = xmldoc.CreateElement("contact")
                    '    a1_person_contact.SetAttribute("type", acid.TYPE_MAIL)
                    '    If String.IsNullOrEmpty(acid.MAIL_NO) Then
                    '        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    '    Else
                    '        a1_person_contact_address = xmldoc.CreateElement("address")
                    '        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.MAIL_NO), strNAV, acid.MAIL_NO))
                    '        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.MAIL_CITY), strNAV, acid.MAIL_CITY))
                    '        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.MAIL_ADDRESS), "", acid.MAIL_ADDRESS))
                    '        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.MAIL_STATE), strNAV, acid.MAIL_STATE))
                    '        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.MAIL_COUNTRY), strNAV, acid.MAIL_COUNTRY))
                    '        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.MAIL_ZIP), strNAV, acid.MAIL_ZIP))
                    '        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.MAIL_NATION), strNAV, acid.MAIL_NATION))

                    '        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MPHONE, acid.MAIL_PHONE)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MFAX, acid.MAIL_FAX)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MCELL, acid.MAIL_CELL)
                    '        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MMAIL, acid.MAIL_EMAIL)

                    '        a1_person_contact.AppendChild(a1_person_contact_address)
                    '        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    '    End If
                    '    a1_person.AppendChild(a1_person_contact)

                    '    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    '    a1_person_iddoc.SetAttribute("type", "99")
                    '    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    '    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(acid.CITIZEN_ID), strNAV, acid.CITIZEN_ID))
                    '    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(acid.CITIZEN_OPN_BY), strNAV, acid.CITIZEN_OPN_BY))
                    '    a1_person_iddoc.SetAttribute("issuedate", FormatDate(acid.CITIZEN_OPN))
                    '    a1_person_iddoc.SetAttribute("expiredate", FormatDate(acid.CITIZEN_EXPIRED))
                    '    a1_person.AppendChild(a1_person_iddoc)
                    '    a1_report.AppendChild(a1_person)
                    'Next

                    ''===================== END ACID

                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE)
                    If obj.P2_FLG_TYPE = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), strNAV, obj.P2_CUST_FNAME))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), strNAV, obj.P2_CUST_LNAME))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY) Or obj.P2_NATIONALITY = "OTHER", "STATELESS", obj.P2_NATIONALITY))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), "", obj.P2_CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME), "", obj.P2_CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                    End If
                    a1_person.AppendChild(a1_person_name)

                    If (obj.P2_FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_CODE), "99", obj.P2_OCCUPATION_CODE))
                        If (obj.P2_OCCUPATION_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_DESC), strNAV, obj.P2_OCCUPATION_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME_NO), strNAV, obj.P2_HOME_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME_CITY), strNAV, obj.P2_HOME_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME_ADDRESS), "", obj.P2_HOME_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME_STATE), strNAV, obj.P2_HOME_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME_COUNTRY), strNAV, obj.P2_HOME_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME_ZIP), strNAV, obj.P2_HOME_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME_NATION), strNAV, obj.P2_HOME_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HPHONE, obj.P2_HOME_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HFAX, obj.P2_HOME_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK_NO), strNAV, obj.P2_WORK_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK_CITY), strNAV, obj.P2_WORK_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK_ADDRESS), "", obj.P2_WORK_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK_STATE), strNAV, obj.P2_WORK_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK_COUNTRY), strNAV, obj.P2_WORK_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK_ZIP), strNAV, obj.P2_WORK_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK_NATION), strNAV, obj.P2_WORK_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WPHONE, obj.P2_WORK_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WFAX, obj.P2_WORK_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NO), strNAV, obj.P2_MAIL_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL_CITY), strNAV, obj.P2_MAIL_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ADDRESS), "", obj.P2_MAIL_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL_STATE), strNAV, obj.P2_MAIL_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL_COUNTRY), strNAV, obj.P2_MAIL_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ZIP), strNAV, obj.P2_MAIL_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NATION), strNAV, obj.P2_MAIL_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MPHONE, obj.P2_MAIL_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MFAX, obj.P2_MAIL_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MCELL, obj.P2_MAIL_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MMAIL, obj.P2_MAIL_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID), strNAV, obj.P2_CITIZEN_ID))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY), strNAV, obj.P2_CITIZEN_OPN_BY))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                a1_report.AppendChild(a1_person)

                '======= ส่วนที่ 2 ข้อมูลผู้ร่วมทำธุรกรรม, ผู้มอบอำนาจ ========

                '================= FROM_ACID
                If (obj.F_COTRAN = "SEND" Or obj.F_COTRAN = "BOTH") Then

                    Dim qryAcidFrom = (From tblAmlo In AMLO1059Entity.AMLO1059_ACID_FROM
                                       Where tblAmlo.TRAN_DATE = obj.P3_TRANS_DATE And tblAmlo.ACID = obj.FROM_ACID)
                    For Each acid As AMLO1059_ACID_FROM In qryAcidFrom
                        a1_person = xmldoc.CreateElement("person")
                        a1_person.SetAttribute("value", "RELATED-PERSON")
                        'a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                        a1_person.SetAttribute("relationship", "COTRAN")
                        'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                        a1_person_name = xmldoc.CreateElement("name")
                        a1_person_name.SetAttribute("type", acid.FLG_TYPE)
                        If acid.FLG_TYPE = "PERSON" Then
                            a1_person_name.SetAttribute("title", acid.SALUTATION)
                            a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(acid.CUST_FNAME), strNAV, acid.CUST_FNAME))
                            'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                            a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(acid.CUST_LNAME), strNAV, acid.CUST_LNAME))
                            'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                            a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(acid.NATIONALITY) Or acid.NATIONALITY = "OTHER", "STATELESS", acid.NATIONALITY))
                        Else
                            a1_person_name.SetAttribute("title", acid.SALUTATION)
                            Dim legalName = IIf(String.IsNullOrEmpty(acid.CUST_FNAME), "", acid.CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_MNAME), "", acid.CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_LNAME), "", acid.CUST_LNAME)
                            a1_person_name.SetAttribute("firstname", legalName)
                            a1_person_name.SetAttribute("legalpersonid", strNAV)
                        End If
                        a1_person.AppendChild(a1_person_name)
                        a1_report.AppendChild(a1_person)

                        '=== occupation
                        If (acid.FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(acid.WORK_NO)) Then
                            a1_person_occupation = xmldoc.CreateElement("occupation")
                            a1_person_occupation.SetAttribute("companyname", strNAV)
                            'a1_person_occupation.SetAttribute("businesstype", XXX)
                            'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                            a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(acid.OCCUPATION_CODE), "99", acid.OCCUPATION_CODE))
                            If (acid.OCCUPATION_CODE = "99") Then
                                a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(acid.OCCUPATION_DESC), strNAV, acid.OCCUPATION_DESC))
                            End If
                            a1_person.AppendChild(a1_person_occupation)
                        End If

                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_HOME)
                        'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.HOME_NO), strNAV, acid.HOME_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.HOME_CITY), strNAV, acid.HOME_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.HOME_ADDRESS), "", acid.HOME_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.HOME_STATE), strNAV, acid.HOME_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.HOME_COUNTRY), strNAV, acid.HOME_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.HOME_ZIP), strNAV, acid.HOME_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.HOME_NATION), strNAV, acid.HOME_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                        'a1_person_contact_address_othercontact_oc
                        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HPHONE, acid.HOME_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HFAX, acid.HOME_FAX)
                        'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                        'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                        'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                        'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                        a1_person.AppendChild(a1_person_contact)
                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                        'ที่อยุ่ที่ทำงาน
                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_WORK)
                        If String.IsNullOrEmpty(acid.WORK_NO) Then
                            a1_person_contact.SetAttribute("noinfo", "TRUE")
                        Else
                            a1_person_contact_address = xmldoc.CreateElement("address")
                            a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.WORK_NO), strNAV, acid.WORK_NO))
                            a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.WORK_CITY), strNAV, acid.WORK_CITY))
                            a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.WORK_ADDRESS), "", acid.WORK_ADDRESS))
                            a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.WORK_STATE), strNAV, acid.WORK_STATE))
                            a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.WORK_COUNTRY), strNAV, acid.WORK_COUNTRY))
                            a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.WORK_ZIP), strNAV, acid.WORK_ZIP))
                            a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.WORK_NATION), strNAV, acid.WORK_NATION))

                            a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WPHONE, acid.WORK_PHONE)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WFAX, acid.WORK_FAX)

                            a1_person_contact.AppendChild(a1_person_contact_address)
                            a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                        End If
                        a1_person.AppendChild(a1_person_contact)


                        'ที่อยู่ที่ติดต่อ
                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_MAIL)
                        If String.IsNullOrEmpty(acid.MAIL_NO) Then
                            a1_person_contact.SetAttribute("noinfo", "TRUE")
                        Else
                            a1_person_contact_address = xmldoc.CreateElement("address")
                            a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.MAIL_NO), strNAV, acid.MAIL_NO))
                            a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.MAIL_CITY), strNAV, acid.MAIL_CITY))
                            a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.MAIL_ADDRESS), "", acid.MAIL_ADDRESS))
                            a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.MAIL_STATE), strNAV, acid.MAIL_STATE))
                            a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.MAIL_COUNTRY), strNAV, acid.MAIL_COUNTRY))
                            a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.MAIL_ZIP), strNAV, acid.MAIL_ZIP))
                            a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.MAIL_NATION), strNAV, acid.MAIL_NATION))

                            a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MPHONE, acid.MAIL_PHONE)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MFAX, acid.MAIL_FAX)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MCELL, acid.MAIL_CELL)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MMAIL, acid.MAIL_EMAIL)

                            a1_person_contact.AppendChild(a1_person_contact_address)
                            a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                        End If
                        a1_person.AppendChild(a1_person_contact)

                        a1_person_iddoc = xmldoc.CreateElement("iddoc")
                        a1_person_iddoc.SetAttribute("type", "99")
                        a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                        a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(acid.CITIZEN_ID), strNAV, acid.CITIZEN_ID))
                        a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(acid.CITIZEN_OPN_BY), strNAV, acid.CITIZEN_OPN_BY))
                        a1_person_iddoc.SetAttribute("issuedate", FormatDate(acid.CITIZEN_OPN))
                        a1_person_iddoc.SetAttribute("expiredate", FormatDate(acid.CITIZEN_EXPIRED))
                        a1_person.AppendChild(a1_person_iddoc)

                        a1_report.AppendChild(a1_person)
                    Next
                End If

                '================= TO_ACID
                If (obj.F_COTRAN = "RECEIVE" Or obj.F_COTRAN = "BOTH") Then

                    Dim qryAcidTo = (From tblAmlo In AMLO1059Entity.AMLO1059_ACID_TO
                                       Where tblAmlo.TRAN_DATE = obj.P3_TRANS_DATE And tblAmlo.ACID = obj.TO_ACID)
                    For Each acid As AMLO1059_ACID_TO In qryAcidTo
                        a1_person = xmldoc.CreateElement("person")
                        a1_person.SetAttribute("value", "RELATED-PERSON")
                        'a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                        a1_person.SetAttribute("relationship", "COTRAN")
                        'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                        a1_person_name = xmldoc.CreateElement("name")
                        a1_person_name.SetAttribute("type", acid.FLG_TYPE)
                        If acid.FLG_TYPE = "PERSON" Then
                            a1_person_name.SetAttribute("title", acid.SALUTATION)
                            a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(acid.CUST_FNAME), strNAV, acid.CUST_FNAME))
                            'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                            a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(acid.CUST_LNAME), strNAV, acid.CUST_LNAME))
                            'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                            a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(acid.NATIONALITY) Or acid.NATIONALITY = "OTHER", "STATELESS", acid.NATIONALITY))
                        Else
                            a1_person_name.SetAttribute("title", acid.SALUTATION)
                            Dim legalName = IIf(String.IsNullOrEmpty(acid.CUST_FNAME), "", acid.CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_MNAME), "", acid.CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(acid.CUST_LNAME), "", acid.CUST_LNAME)
                            a1_person_name.SetAttribute("firstname", legalName)
                            a1_person_name.SetAttribute("legalpersonid", strNAV)
                        End If
                        a1_person.AppendChild(a1_person_name)
                        a1_report.AppendChild(a1_person)

                        '=== occupation
                        If (acid.FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(acid.WORK_NO)) Then
                            a1_person_occupation = xmldoc.CreateElement("occupation")
                            a1_person_occupation.SetAttribute("companyname", strNAV)
                            'a1_person_occupation.SetAttribute("businesstype", XXX)
                            'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                            a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(acid.OCCUPATION_CODE), "99", acid.OCCUPATION_CODE))
                            If (acid.OCCUPATION_CODE = "99") Then
                                a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(acid.OCCUPATION_DESC), strNAV, acid.OCCUPATION_DESC))
                            End If
                            a1_person.AppendChild(a1_person_occupation)
                        End If

                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_HOME)
                        'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.HOME_NO), strNAV, acid.HOME_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.HOME_CITY), strNAV, acid.HOME_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.HOME_ADDRESS), "", acid.HOME_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.HOME_STATE), strNAV, acid.HOME_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.HOME_COUNTRY), strNAV, acid.HOME_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.HOME_ZIP), strNAV, acid.HOME_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.HOME_NATION), strNAV, acid.HOME_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                        'a1_person_contact_address_othercontact_oc
                        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HPHONE, acid.HOME_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_HFAX, acid.HOME_FAX)
                        'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                        'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                        'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                        'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                        a1_person.AppendChild(a1_person_contact)
                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                        'ที่อยุ่ที่ทำงาน
                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_WORK)
                        If String.IsNullOrEmpty(acid.WORK_NO) Then
                            a1_person_contact.SetAttribute("noinfo", "TRUE")
                        Else
                            a1_person_contact_address = xmldoc.CreateElement("address")
                            a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.WORK_NO), strNAV, acid.WORK_NO))
                            a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.WORK_CITY), strNAV, acid.WORK_CITY))
                            a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.WORK_ADDRESS), "", acid.WORK_ADDRESS))
                            a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.WORK_STATE), strNAV, acid.WORK_STATE))
                            a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.WORK_COUNTRY), strNAV, acid.WORK_COUNTRY))
                            a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.WORK_ZIP), strNAV, acid.WORK_ZIP))
                            a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.WORK_NATION), strNAV, acid.WORK_NATION))

                            a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WPHONE, acid.WORK_PHONE)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_WFAX, acid.WORK_FAX)

                            a1_person_contact.AppendChild(a1_person_contact_address)
                            a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                        End If
                        a1_person.AppendChild(a1_person_contact)


                        'ที่อยู่ที่ติดต่อ
                        a1_person_contact = xmldoc.CreateElement("contact")
                        a1_person_contact.SetAttribute("type", acid.TYPE_MAIL)
                        If String.IsNullOrEmpty(acid.MAIL_NO) Then
                            a1_person_contact.SetAttribute("noinfo", "TRUE")
                        Else
                            a1_person_contact_address = xmldoc.CreateElement("address")
                            a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(acid.MAIL_NO), strNAV, acid.MAIL_NO))
                            a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(acid.MAIL_CITY), strNAV, acid.MAIL_CITY))
                            a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(acid.MAIL_ADDRESS), "", acid.MAIL_ADDRESS))
                            a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(acid.MAIL_STATE), strNAV, acid.MAIL_STATE))
                            a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(acid.MAIL_COUNTRY), strNAV, acid.MAIL_COUNTRY))
                            a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(acid.MAIL_ZIP), strNAV, acid.MAIL_ZIP))
                            a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(acid.MAIL_NATION), strNAV, acid.MAIL_NATION))

                            a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MPHONE, acid.MAIL_PHONE)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MFAX, acid.MAIL_FAX)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MCELL, acid.MAIL_CELL)
                            AddOC(xmldoc, a1_person_contact_address_othercontact, acid.TYPE_MMAIL, acid.MAIL_EMAIL)

                            a1_person_contact.AppendChild(a1_person_contact_address)
                            a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                        End If
                        a1_person.AppendChild(a1_person_contact)

                        a1_person_iddoc = xmldoc.CreateElement("iddoc")
                        a1_person_iddoc.SetAttribute("type", "99")
                        a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                        a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(acid.CITIZEN_ID), strNAV, acid.CITIZEN_ID))
                        a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(acid.CITIZEN_OPN_BY), strNAV, acid.CITIZEN_OPN_BY))
                        a1_person_iddoc.SetAttribute("issuedate", FormatDate(acid.CITIZEN_OPN))
                        a1_person_iddoc.SetAttribute("expiredate", FormatDate(acid.CITIZEN_EXPIRED))
                        a1_person.AppendChild(a1_person_iddoc)

                        a1_report.AppendChild(a1_person)
                    Next
                End If

                '================= END ACID

                If (obj.F_XMLPART2 = "SEND") Then
                    a1_person = xmldoc.CreateElement("person")
                    a1_person.SetAttribute("value", "RELATED-PERSON")
                    a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                    'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE2)
                    If obj.P2_FLG_TYPE2 = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), strNAV, obj.P2_CUST_FNAME2))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), strNAV, obj.P2_CUST_LNAME2))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY2) Or obj.P2_NATIONALITY2 = "OTHER", "STATELESS", obj.P2_NATIONALITY2))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION2)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME2), "", obj.P2_CUST_LNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME2), "", obj.P2_CUST_MNAME2) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME2), "", obj.P2_CUST_LNAME2)
                        a1_person_name.SetAttribute("firstname", legalName)
                        a1_person_name.SetAttribute("legalpersonid", strNAV)
                    End If
                    a1_person.AppendChild(a1_person_name)
                    a1_report.AppendChild(a1_person)

                    '=== occupation
                    If (obj.P2_FLG_TYPE2 = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK2_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_CODE), "99", obj.P2_OCCUPATION2_CODE))
                        If (obj.P2_OCCUPATION2_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION2_DESC), strNAV, obj.P2_OCCUPATION2_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If

                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NO), strNAV, obj.P2_HOME2_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME2_CITY), strNAV, obj.P2_HOME2_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ADDRESS), "", obj.P2_HOME2_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME2_STATE), strNAV, obj.P2_HOME2_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME2_COUNTRY), strNAV, obj.P2_HOME2_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_ZIP), strNAV, obj.P2_HOME2_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME2_NATION), strNAV, obj.P2_HOME2_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HPHONE, obj.P2_HOME2_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_HFAX, obj.P2_HOME2_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NO), strNAV, obj.P2_WORK2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK2_CITY), strNAV, obj.P2_WORK2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ADDRESS), "", obj.P2_WORK2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK2_STATE), strNAV, obj.P2_WORK2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK2_COUNTRY), strNAV, obj.P2_WORK2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_ZIP), strNAV, obj.P2_WORK2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK2_NATION), strNAV, obj.P2_WORK2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WPHONE, obj.P2_WORK2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_WFAX, obj.P2_WORK2_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE2_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL2_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NO), strNAV, obj.P2_MAIL2_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_CITY), strNAV, obj.P2_MAIL2_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ADDRESS), "", obj.P2_MAIL2_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_STATE), strNAV, obj.P2_MAIL2_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_COUNTRY), strNAV, obj.P2_MAIL2_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_ZIP), strNAV, obj.P2_MAIL2_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL2_NATION), strNAV, obj.P2_MAIL2_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MPHONE, obj.P2_MAIL2_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MFAX, obj.P2_MAIL2_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MCELL, obj.P2_MAIL2_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE2_MMAIL, obj.P2_MAIL2_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID2), strNAV, obj.P2_CITIZEN_ID2))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY2), strNAV, obj.P2_CITIZEN_OPN_BY2))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN2))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED2))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                If (obj.F_XMLPART2 = "RECEIVE") Then

                    a1_person = xmldoc.CreateElement("person")
                    a1_person.SetAttribute("value", "RELATED-PERSON")
                    a1_person.SetAttribute("relationship", obj.F_RELATIONSHIP)
                    'ไม่จำเป็นต้อa1_person.SetAttribute("relationshipdesc", XXX)

                    a1_person_name = xmldoc.CreateElement("name")
                    a1_person_name.SetAttribute("type", obj.P2_FLG_TYPE)
                    If obj.P2_FLG_TYPE = "PERSON" Then
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        a1_person_name.SetAttribute("firstname", IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), strNAV, obj.P2_CUST_FNAME))
                        'ไม่จำเป็นต้องระบุ a1_person_name.SetAttribute("middlename", XXX)
                        a1_person_name.SetAttribute("lastname", IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), strNAV, obj.P2_CUST_LNAME))
                        'ไม่ส่ง a1_person_name.SetAttribute("dateofbirth", XXX)
                        a1_person_name.SetAttribute("nationality", IIf(String.IsNullOrEmpty(obj.P2_NATIONALITY) Or obj.P2_NATIONALITY = "OTHER", "STATELESS", obj.P2_NATIONALITY))
                    Else
                        a1_person_name.SetAttribute("title", obj.P2_SALUTATION)
                        Dim legalName = IIf(String.IsNullOrEmpty(obj.P2_CUST_FNAME), "", obj.P2_CUST_LNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_MNAME), "", obj.P2_CUST_MNAME) + " " + IIf(String.IsNullOrEmpty(obj.P2_CUST_LNAME), "", obj.P2_CUST_LNAME)
                        a1_person_name.SetAttribute("firstname", legalName)
                        a1_person_name.SetAttribute("legalpersonid", strNAV)
                    End If
                    a1_person.AppendChild(a1_person_name)
                    a1_report.AppendChild(a1_person)

                    '=== occupation
                    If (obj.P2_FLG_TYPE = "PERSON" And Not String.IsNullOrEmpty(obj.P2_WORK_NO)) Then
                        a1_person_occupation = xmldoc.CreateElement("occupation")
                        a1_person_occupation.SetAttribute("companyname", strNAV)
                        'a1_person_occupation.SetAttribute("businesstype", XXX)
                        'a1_person_occupation.SetAttribute("businesstype_desc", XXX)
                        a1_person_occupation.SetAttribute("occ_type", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_CODE), "99", obj.P2_OCCUPATION_CODE))
                        If (obj.P2_OCCUPATION_CODE = "99") Then
                            a1_person_occupation.SetAttribute("occ_desc", IIf(String.IsNullOrEmpty(obj.P2_OCCUPATION_DESC), strNAV, obj.P2_OCCUPATION_DESC))
                        End If
                        a1_person.AppendChild(a1_person_occupation)
                    End If


                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_HOME)
                    'ไม่จำเป็นต้องระบุ a1_person_contact.SetAttribute("noinfo", XXX)

                    a1_person_contact_address = xmldoc.CreateElement("address")
                    a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_HOME_NO), strNAV, obj.P2_HOME_NO))
                    a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_HOME_CITY), strNAV, obj.P2_HOME_CITY))
                    a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_HOME_ADDRESS), "", obj.P2_HOME_ADDRESS))
                    a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_HOME_STATE), strNAV, obj.P2_HOME_STATE))
                    a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_HOME_COUNTRY), strNAV, obj.P2_HOME_COUNTRY))
                    a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_HOME_ZIP), strNAV, obj.P2_HOME_ZIP))
                    a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_HOME_NATION), strNAV, obj.P2_HOME_NATION))

                    a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")

                    'a1_person_contact_address_othercontact_oc
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HPHONE, obj.P2_HOME_PHONE)
                    AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_HFAX, obj.P2_HOME_FAX)
                    'a1_person_contact_address_othercontact_oc = xmldoc.CreateElement("oc")  'ถ้ามี ระบุได้มากกว่า 1
                    'a1_person_contact_address_othercontact_oc.SetAttribute("type", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("value", XXX)
                    'a1_person_contact_address_othercontact_oc.SetAttribute("ext", XXX)
                    a1_person.AppendChild(a1_person_contact)
                    a1_person_contact.AppendChild(a1_person_contact_address)
                    a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)

                    'ที่อยุ่ที่ทำงาน
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_WORK)
                    If String.IsNullOrEmpty(obj.P2_WORK_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_WORK_NO), strNAV, obj.P2_WORK_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_WORK_CITY), strNAV, obj.P2_WORK_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_WORK_ADDRESS), "", obj.P2_WORK_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_WORK_STATE), strNAV, obj.P2_WORK_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_WORK_COUNTRY), strNAV, obj.P2_WORK_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_WORK_ZIP), strNAV, obj.P2_WORK_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_WORK_NATION), strNAV, obj.P2_WORK_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WPHONE, obj.P2_WORK_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_WFAX, obj.P2_WORK_FAX)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)


                    'ที่อยู่ที่ติดต่อ
                    a1_person_contact = xmldoc.CreateElement("contact")
                    a1_person_contact.SetAttribute("type", obj.P2_TYPE_MAIL)
                    If String.IsNullOrEmpty(obj.P2_MAIL_NO) Then
                        a1_person_contact.SetAttribute("noinfo", "TRUE")
                    Else
                        a1_person_contact_address = xmldoc.CreateElement("address")
                        a1_person_contact_address.SetAttribute("no", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NO), strNAV, obj.P2_MAIL_NO))
                        a1_person_contact_address.SetAttribute("subdistrict", IIf(String.IsNullOrEmpty(obj.P2_MAIL_CITY), strNAV, obj.P2_MAIL_CITY))
                        a1_person_contact_address.SetAttribute("address1", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ADDRESS), "", obj.P2_MAIL_ADDRESS))
                        a1_person_contact_address.SetAttribute("district", IIf(String.IsNullOrEmpty(obj.P2_MAIL_STATE), strNAV, obj.P2_MAIL_STATE))
                        a1_person_contact_address.SetAttribute("province", IIf(String.IsNullOrEmpty(obj.P2_MAIL_COUNTRY), strNAV, obj.P2_MAIL_COUNTRY))
                        a1_person_contact_address.SetAttribute("zipcode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_ZIP), strNAV, obj.P2_MAIL_ZIP))
                        a1_person_contact_address.SetAttribute("countrycode", IIf(String.IsNullOrEmpty(obj.P2_MAIL_NATION), strNAV, obj.P2_MAIL_NATION))

                        a1_person_contact_address_othercontact = xmldoc.CreateElement("othercontact")
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MPHONE, obj.P2_MAIL_PHONE)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MFAX, obj.P2_MAIL_FAX)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MCELL, obj.P2_MAIL_CELL)
                        AddOC(xmldoc, a1_person_contact_address_othercontact, obj.P2_TYPE_MMAIL, obj.P2_MAIL_EMAIL)

                        a1_person_contact.AppendChild(a1_person_contact_address)
                        a1_person_contact_address.AppendChild(a1_person_contact_address_othercontact)
                    End If
                    a1_person.AppendChild(a1_person_contact)

                    a1_person_iddoc = xmldoc.CreateElement("iddoc")
                    a1_person_iddoc.SetAttribute("type", "99")
                    a1_person_iddoc.SetAttribute("typedesc", "ไม่สามารถระบุได้")
                    a1_person_iddoc.SetAttribute("idno", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_ID), strNAV, obj.P2_CITIZEN_ID))
                    a1_person_iddoc.SetAttribute("issueby", IIf(String.IsNullOrEmpty(obj.P2_CITIZEN_OPN_BY), strNAV, obj.P2_CITIZEN_OPN_BY))
                    a1_person_iddoc.SetAttribute("issuedate", FormatDate(obj.P2_CITIZEN_OPN))
                    a1_person_iddoc.SetAttribute("expiredate", FormatDate(obj.P2_CITIZEN_EXPIRED))
                    a1_person.AppendChild(a1_person_iddoc)
                End If

                '======= ส่วนที่ 3 ข้อเท็จจริงเกี่ยวกับการทำธุรกรรม ========
                Dim a1_tsc As XmlElement
                Dim a1_tsc_tscentry As XmlElement 'ระบุได้มากกว่า 1
                Dim a1_tsc_tscentry_typeoftsc As XmlElement
                Dim a1_tsc_tscentry_transferdetail As XmlElement
                Dim a1_tsc_tscentry_amount As XmlElement
                Dim a1_tsc_totalamount As XmlElement
                Dim a1_tsc_benfperson As XmlElement
                Dim a1_tsc_objective As XmlElement

                a1_tsc = xmldoc.CreateElement("tsc")
                a1_tsc.SetAttribute("date", FormatDate(obj.P3_TRANS_DATE))

                a1_tsc_tscentry = xmldoc.CreateElement("tscentry")

                a1_tsc_tscentry_typeoftsc = xmldoc.CreateElement("typeoftsc")
                a1_tsc_tscentry_typeoftsc.SetAttribute("transtype", IIf(String.IsNullOrEmpty(obj.P3_TRANS_TYPE), strNAV, obj.P3_TRANS_TYPE))
                a1_tsc_tscentry_typeoftsc.SetAttribute("type", IIf(String.IsNullOrEmpty(obj.P3_TRAN_CODE), strNAV, obj.P3_TRAN_CODE))
                If obj.P3_TRAN_CODE = "OTHER" Then
                    a1_tsc_tscentry_typeoftsc.SetAttribute("desc", "INBK")
                End If
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_typeoftsc)


                a1_tsc_tscentry_transferdetail = xmldoc.CreateElement("transferdetail")
                'ผู้โอน
                a1_tsc_tscentry_transferdetail.SetAttribute("sendaccountno", obj.P3_FORACID)
                If (String.IsNullOrEmpty(obj.P3_FORACID)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendrefno", obj.P3_TRAN_ID)
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("sendfullname", IIf(String.IsNullOrEmpty(obj.P3_CUST_NAME), strNAV, obj.P3_CUST_NAME))

                If obj.KEY_FLG = "1" Or obj.KEY_FLG = "2" Or obj.KEY_FLG = "5" Or obj.KEY_FLG = "6" Or obj.KEY_FLG = "7" Or obj.KEY_FLG = "9" Then
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME) Or obj.P3_COMPANY_NAME = "NAV", "ธนาคารอาคารสงเคราะห์", obj.P3_COMPANY_NAME)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", strOrg)
                ElseIf obj.KEY_FLG = "8" Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", "ธนาคารแห่งประเทศไทย")
                Else
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME), "NAV", obj.P3_COMPANY_NAME)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendorg", strOrg)
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("sendorgcountry", "TH")
                a1_tsc_tscentry_transferdetail.SetAttribute("sendaddress", obj.P3_HOME_ADDRESS)
                'a1_tsc_tscentry_transferdetail.SetAttribute("sendcontactaddress", XXX)
                If (String.IsNullOrEmpty(obj.P3_HOME_ADDRESS)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidtype", obj.P3_LICENSE)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidno", obj.P3_CITIZEN_ID)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidissuer", obj.P3_CITIZEN_BY)
                    a1_tsc_tscentry_transferdetail.SetAttribute("sendidexpiredate", FormatDate(obj.P3_CITIZEN_EXPIRED))
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("senddateofbirth", FormatDate(obj.P3_CUST_DOB))
                a1_tsc_tscentry_transferdetail.SetAttribute("sendplaceofbirth", obj.P3_BORN_PLACE)
                'ผู้รับ
                a1_tsc_tscentry_transferdetail.SetAttribute("recaccountno", IIf(String.IsNullOrEmpty(obj.P3_FORACID2), strNAV, obj.P3_FORACID2))
                If (String.IsNullOrEmpty(obj.P3_FORACID)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("recrefno", obj.P3_TRAN_ID2)
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("recfullname", IIf(String.IsNullOrEmpty(obj.P3_CUST_NAME2), strNAV, obj.P3_CUST_NAME2))

                If obj.KEY_FLG = "3" Or obj.KEY_FLG = "4" Or obj.KEY_FLG = "5" _
                    Or obj.KEY_FLG = "6" Or obj.KEY_FLG = "7" Or obj.KEY_FLG = "8" _
                    Or obj.KEY_FLG = "9" Then
                    strOrg = IIf(String.IsNullOrEmpty("P3_COMPANY_NAME2") Or obj.P3_COMPANY_NAME2 = "NAV", "ธนาคารอาคารสงเคราะห์", obj.P3_COMPANY_NAME2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recorg", strOrg)
                Else
                    strOrg = IIf(String.IsNullOrEmpty(obj.P3_COMPANY_NAME2), "NAV", obj.P3_COMPANY_NAME2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recorg", strOrg)
                End If

                a1_tsc_tscentry_transferdetail.SetAttribute("recorgcountry", "TH")
                a1_tsc_tscentry_transferdetail.SetAttribute("recaddress", IIf(String.IsNullOrEmpty(obj.P3_HOME_ADDRESS2), strNAV, obj.P3_HOME_ADDRESS2))
                'a1_tsc_tscentry_transferdetail.SetAttribute("reccontactaddress", XXX)
                If (String.IsNullOrEmpty(obj.P3_HOME_ADDRESS2)) Then
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidtype", obj.P3_LICENSE2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidno", obj.P3_CITIZEN_ID2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidissuer", obj.P3_CITIZEN_BY2)
                    a1_tsc_tscentry_transferdetail.SetAttribute("recidexpiredate", FormatDate(obj.P3_CITIZEN_EXPIRED2))
                End If
                a1_tsc_tscentry_transferdetail.SetAttribute("recdateofbirth", FormatDate(obj.P3_CUST_DOB2))
                a1_tsc_tscentry_transferdetail.SetAttribute("recplaceofbirth", obj.P3_BORN_PLACE2)
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_transferdetail)


                a1_tsc_tscentry_amount = xmldoc.CreateElement("amount")
                a1_tsc_tscentry_amount.SetAttribute("valueinbaht", String.Format("{0:F2}", obj.P3_TRAN_AMT))
                a1_tsc_tscentry_amount.SetAttribute("valueinbahttxt", obj.P3_THAI_BAHT)
                'ธอส ไม่มีเงินต่างประเทศ
                'a1_tsc_tscentry_amount.SetAttribute("value", XXX)
                'a1_tsc_tscentry_amount.SetAttribute("curr", XXX)
                'a1_tsc_tscentry_amount.SetAttribute("exchangerate", XXX)
                a1_tsc_tscentry.AppendChild(a1_tsc_tscentry_amount)

                a1_tsc_totalamount = xmldoc.CreateElement("totalamount")
                a1_tsc_totalamount.SetAttribute("valueinbaht", String.Format("{0:F2}", obj.P3_TRAN_AMT))
                a1_tsc_totalamount.SetAttribute("valueinbahttxt", obj.P3_THAI_BAHT)
                a1_tsc.AppendChild(a1_tsc_totalamount)

                'a1_tsc_benfperson = xmldoc.CreateElement("benfperson")
                'a1_tsc_benfperson.SetAttribute("firstname", XXX)
                'a1_tsc_benfperson.SetAttribute("middlename", XXX)
                'a1_tsc_benfperson.SetAttribute("lastname", XXX)

                a1_tsc_objective = xmldoc.CreateElement("objective")
                a1_tsc_objective.InnerText = "เพื่อทำธุรกรรม"
                'a1_tsc_objective.SetAttribute("type", XXX)
                a1_tsc.AppendChild(a1_tsc_objective)

                a1_tsc.AppendChild(a1_tsc_tscentry)
                a1_report.AppendChild(a1_tsc)

                '======= ส่วนที่ 4 วันที่บันทึกรายงาน ========
                Dim a1_record As XmlElement
                a1_record = xmldoc.CreateElement("record")
                a1_record.SetAttribute("date", FormatDate(Date.Today))
                a1_report.AppendChild(a1_record)

            Next

            '// Save to the XML file
            'xmldoc.Save(filePath)
            Dim ansiWriter As StreamWriter
            ansiWriter = New StreamWriter(filePath, False, Encoding.UTF8)
            xmldoc.Save(ansiWriter)

            ansiWriter.Close()
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Private Sub AddOC(ByRef doc As XmlDocument, ByRef othercontact As XmlElement, ByVal vtype As String, ByVal vvalue As String)
        Dim oc As XmlElement
        vvalue = IIf(String.IsNullOrEmpty(vvalue), "", vvalue)
        If Trim(vvalue) <> "" Then
            Dim Type = doc.CreateAttribute("type")
            Dim value = doc.CreateAttribute("value")

            If vtype = "PHONE" Or vtype = "FAX" Or vtype = "MOBILE" Then
                value.Value = CheckDigit(vvalue)
            Else
                value.Value = vvalue
            End If

            If value.Value <> "" Then
                oc = doc.CreateElement("oc")
                othercontact.AppendChild(oc)
                Type.Value = vtype
                oc.Attributes.Append(Type)
                oc.Attributes.Append(value)
            End If
        End If
    End Sub
    Function CheckDigit(ByVal sData As String) As String
        'Dim Status As Boolean
        Dim NewNumber As String
        'วน Loop เช็คค่า ทีละตำแหน่ง ถ้าไม่ใช่ ตัวเลข 0-9 และ "-"
        Dim i As Long
        NewNumber = ""
        For i = 0 To sData.Length - 1
            Select Case sData.Substring(i, 1)
                Case "0" To "9" : NewNumber = NewNumber & sData.Substring(i, 1)
                Case "-" : NewNumber = NewNumber & sData.Substring(i, 1)
                Case Else
                    'ถ้า Format ไม่ถูกต้องให้ส่งค่า "" เพื่อไม่ส่งค่าไป ปปง.
                    NewNumber = ""
                    Exit For
            End Select
        Next i

        CheckDigit = NewNumber
    End Function
    Private Function FormatDate(ByVal iDate? As Date) As String
        Dim strDate As String = ""
        If Not (IsNothing(iDate) OrElse IsDBNull(iDate) OrElse iDate.Equals(Date.MinValue)) Then
            strDate = Format(iDate, "yyyy-MM-dd")
        End If
        Return strDate
    End Function

    Private Sub GenDocumentNO(ByVal idList As List(Of Integer))

        Dim SOL_ID, strDOCUMENTNO, prevSOLID, YearMonth As String
        Dim DocumentNo As Integer
        'ใส่เลขที่เอกสาร
        Dim AMLO1059Entity = New AMLO1059Entities
        Dim qryAmlo = (From tblAmlo In AMLO1059Entity.AMLO1059
                  Where idList.Contains(tblAmlo.ID)
                  Order By tblAmlo.INIT_SOL_ID, tblAmlo.P3_TRANS_DATE).ToList

        'ดึงข้อมูลเพื่อใส่เลขที่เอกสาร
        prevSOLID = ""
        DocumentNo = 0
        For i = 0 To qryAmlo.Count - 1
            Dim obj = qryAmlo(i)
            strDOCUMENTNO = IIf(String.IsNullOrEmpty(obj.DCN_DOCUMENTNO), "", obj.DCN_DOCUMENTNO)
            'ถ้ามีเลขแล้วไม่ต้องใส่ใหม่
            If strDOCUMENTNO = "" Then
                SOL_ID = obj.INIT_SOL_ID
                YearMonth = String.Format("{0:yyyyMM}", obj.P3_TRANS_DATE)

                'ไปหาเลขที่เอกสาร แยกตาม SOL
                If SOL_ID <> prevSOLID Then
                    DocumentNo = (From tblAmlo In AMLO1059Entity.AMLO1059
                                  Where tblAmlo.INIT_SOL_ID = SOL_ID And tblAmlo.DCN_YEARMONTH = YearMonth _
                                  Select tblAmlo.DCN_DOCUMENTNO).Max()
                End If
                DocumentNo = IIf(String.IsNullOrEmpty(DocumentNo), 0, DocumentNo)

                DocumentNo = DocumentNo + 1

                'Update เลขที่เอกสารลง Table
                strDOCUMENTNO = Right("000000" & DocumentNo, 6)
                obj.DCN_YEARMONTH = String.Format("{0:yyyyMM}", obj.P3_TRANS_DATE)
                obj.DCN_DOCUMENTNO = strDOCUMENTNO

                AMLO1059Entity.SaveChanges()

                prevSOLID = obj.INIT_SOL_ID
            End If
        Next
    End Sub
End Class
